Qt中的焦点事件
2016-10-31 10:28
1046 查看
在应用程序中,都会有一个当前窗口,即当前获得焦点事件的窗口,这个窗口可以接受键盘的输入。当应用有多个窗口时就要使用焦点事件了!
Qt中有很好的焦点事件管理,我在这里抛砖引玉了。一个空间要先设置它焦点事件的模式,即窗口如何接受焦点事件(通过鼠标单击、Tab键、不接受焦点事件等)
就是设置焦点事件模式的函数,其中函数的参数为
如果想通过单击鼠标获取焦点事件,那么就可以选择参数Qt::ClickFocus,其他不赘述。
当前有焦点事件的窗口只能有一个,当一个窗口获取焦点事件或失去焦点事件时,可能需要相应的操作,或者如何判断一个才窗口有没有焦点事件。Qt中亦有相应的函数。
这两个就是窗口获取或失去焦点事件的函数,需要我们重写(好多窗口都是从QWidget继承这两个函数的)
bool hasFocus () const
这个函数就是判断当前窗口有没有焦点事件的,返回布尔值。
这两个函数就是设置或清除焦点事件的。
要想知道更多,只需要在“Qt助手”的“索引”中输入“Focus”,自己动手吧!!
Qt中有很好的焦点事件管理,我在这里抛砖引玉了。一个空间要先设置它焦点事件的模式,即窗口如何接受焦点事件(通过鼠标单击、Tab键、不接受焦点事件等)
void | setFocusPolicy ( Qt::FocusPolicy policy ) |
Constant | Value | Description |
---|---|---|
Qt::TabFocus | 0x1 | the widget accepts focus by tabbing. |
Qt::ClickFocus | 0x2 | the widget accepts focus by clicking. |
Qt::StrongFocus | TabFocus | ClickFocus | 0x8 | the widget accepts focus by both tabbing and clicking. On Mac OS X this will also be indicate that the widget accepts tab focus when in 'Text/List focus mode'. |
Qt::WheelFocus | StrongFocus | 0x4 | like Qt::StrongFocus plus the widget accepts focus by using the mouse wheel. |
Qt::NoFocus | 0 | the widget does not accept focus. |
当前有焦点事件的窗口只能有一个,当一个窗口获取焦点事件或失去焦点事件时,可能需要相应的操作,或者如何判断一个才窗口有没有焦点事件。Qt中亦有相应的函数。
void QWidget::focusInEvent ( QFocusEvent * event ) [virtual
protected]
void QWidget::focusOutEvent ( QFocusEvent * event ) [virtual
protected]
这两个就是窗口获取或失去焦点事件的函数,需要我们重写(好多窗口都是从QWidget继承这两个函数的)bool hasFocus () const
这个函数就是判断当前窗口有没有焦点事件的,返回布尔值。
void QWidget::setFocus ( Qt::FocusReason reason )
void QWidget::clearFocus ()
这两个函数就是设置或清除焦点事件的。要想知道更多,只需要在“Qt助手”的“索引”中输入“Focus”,自己动手吧!!
相关文章推荐
- Qt焦点事件
- Qt焦点事件
- Qt焦点事件
- QT 获取焦点失去焦点事件
- Qt中的焦点事件
- qt焦点事件响应捕捉处理,事件过滤器
- Qt QTableView焦点事件
- Qt获得焦点和失去焦点处理事件 (Focus事件)
- Qt获得焦点和失去焦点处理事件 (Focus事件)
- 关键词:键盘触发事件、QList用法、清除/获得焦点、CSS、Qt初学教程
- Qt焦点事件
- QT事件过滤器、事件重载和焦点事件
- Qt获得焦点和失去焦点处理事件 (Focus事件)
- Qt之Tab键实现(自由切换焦点)—— 采用事件过滤器处理
- QT的键盘事件及焦点设置
- Qt获得焦点和失去焦点处理事件 (Focus事件)
- Qt中的焦点事件
- Qt中的焦点事件
- Qt中使用事件过滤器来处理键盘焦点
- Qt中使用事件过滤器来处理键盘焦点