想取消qtableview获取焦点的功能,查了qt4.1.0文档,仔细看了下,用setFocusPolicy设置
tableView->setFocusPolicy(Qt::NoFocus)
其中qt4.1.0文档关于enum Qt::FocusPolicy说明如下:
This enum type defines the various policies a widget can have with respect to acquiring keyboard focus.
| 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. |
而关于enum Qt::FocusReason的说明如下:
This enum specifies why the focus changed. It will be passed through QWidget::setFocus and can be retrieved in the QFocusEvent sent to the widget upon focus change.
| Constant | Value | Description |
|---|---|---|
| Qt::MouseFocusReason | 0 | A mouse action occurred. |
| Qt::TabFocusReason | 1 | The Tab key was pressed. |
| Qt::BacktabFocusReason | 2 | A Backtab occurred. The input for this may include the Shift or Control keys; e.g. Shift+Tab. |
| Qt::ActiveWindowFocusReason | 3 | The window system made this window either active or inactive. |
| Qt::PopupFocusReason | 4 | The application opened/closed a popup that grabbed/released the keyboard focus. |
| Qt::ShortcutFocusReason | 5 | The user typed a label's buddy shortcut |
| Qt::MenuBarFocusReason | 6 | The menu bar took focus. |
| Qt::OtherFocusReason | 7 | Another reason, usually application-specific. No good reason, really. |
原来两者区别挺大的,学习了.
资料参考:Qt 4.1.0文档
在Qt中,为了阻止QTableView获取键盘焦点,可以使用setFocusPolicy方法,将其设置为Qt::NoFocus。这确保了视图不会接收键盘输入。在理解Qt的FocusPolicy和FocusReason枚举类型后,可以更好地控制焦点行为。
1454

被折叠的 条评论
为什么被折叠?



