概述:
事件是Qt中比较重要的一部分,在初期如果理解不当学习可能会比较困难,这里提一嘴当初教我的那位老师水平是真的高,让我很轻易的就理解了事件的概念。
在平时我们见到那些界面上的某些快捷键就有可能是事件做的,例如ESC关闭窗口,Enter提交或者登录这种类似的,这也是事件的强大之处。
1. 概念
那么到底什么是事件呢?事件都有什么类型?
事件就是我们在操作一件事发出的一个信号,简称为事件。例如我点击了一下鼠标,这个事就叫做事件,Qt会捕捉这个事件,让你进行判断,然后可以对应相应的逻辑。
当然事件不止一种,我们可以在Qt的Assistant中查找到Qevent的类型,种类非常繁多,我们可以根据自己平时运用到的去练习。
2. 类型图
常量 值 描述
QEvent::None 0 不是一个事件
QEvent::ActionAdded 114 一个新 action 被添加(QActionEvent)
QEvent::ActionChanged 113 一个 action 被改变(QActionEvent)
QEvent::ActionRemoved 115 一个 action 被移除(QActionEvent)
QEvent::ActivationChange 99 Widget 的顶层窗口激活状态发生了变化
QEvent::ApplicationActivate 121 这个枚举已被弃用,使用 ApplicationStateChange 代替
QEvent::ApplicationActivated ApplicationActivate 这个枚举已被弃用,使用 ApplicationStateChange 代替
QEvent::ApplicationDeactivate 122 这个枚举已被弃用,使用 ApplicationStateChange 代替
QEvent::ApplicationFontChange 36 应用程序的默认字体发生了变化
QEvent::ApplicationLayoutDirectionChange 37 应用程序的默认布局方向发生了变化
QEvent::ApplicationPaletteChange 38 应用程序的默认调色板发生了变化
QEvent::ApplicationStateChange 214 应用程序的状态发生了变化
QEvent::ApplicationWindowIconChange 35 应用程序的图标发生了变化
QEvent::ChildAdded 68 一个对象获得孩子(QChildEvent)
QEvent::ChildPolished 69 一个部件的孩子被抛光(QChildEvent)
QEvent::ChildRemoved 71 一个对象时区孩子(QChildEvent)
QEvent::Clipboard 40 剪贴板的内容发生改变
QEvent::Close 19 Widget 被关闭(QCloseEvent)
QEvent::CloseSoftwareInputPanel 200 一个部件要关闭软件输入面板(SIP)
QEvent::ContentsRectChange 178 部件内容区域的外边距发生改变
QEvent::ContextMenu 82 上下文弹出菜单(QContextMenuEvent)
QEvent::CursorChange 183 部件的鼠标发生改变
QEvent::DeferredDelete 52 对象被清除后将被删除(QDeferredDeleteEvent)
QEvent::DragEnter 60 在拖放操作期间鼠标进入窗口部件(QDragEnterEvent)
QEvent::DragLeave 62 在拖放操作期间鼠标离开窗口部件(QDragLeaveEvent)
QEvent::DragMove 61 拖放操作正在进行(QDragMoveEvent)
QEvent::Drop 63 拖放操作完成(QDropEvent)
QEvent::DynamicPropertyChange 170 动态属性已添加、更改或从对象中删除
QEvent::EnabledChange 98 部件的 enabled 状态已更改
QEvent::Enter 10 鼠标进入部件的边界(QEnterEvent)
QEvent::EnterEditFocus 150 编辑部件获得焦点进行编辑,必须定义 QT_KEYPAD_NAVIGATION
QEvent::EnterWhatsThisMode 124 当应用程序进入“What’s This?”模式,发送到 toplevel 顶层部件
QEvent::Expose 206 当其屏幕上的内容无效,发送到窗口,并需要从后台存储刷新
QEvent::FileOpen 116 文件打开请求(QFileOpenEvent)
QEvent::FocusIn 8 部件或窗口获得键盘焦点(QFocusEvent)
QEvent::FocusOut 9 部件或窗口失去键盘焦点(QFocusEvent)
QEvent::FocusAboutToChange 23 部件或窗口焦点即将改变(QFocusEvent)
QEvent::FontChange 97 部件的字体发生改变
QEvent::Gesture 198 触发了一个手势(QGestureEvent)
QEvent::GestureOverride 202 触发了手势覆盖(QGestureEvent)
QEvent::GrabKeyboard 188 Item 获得键盘抓取(仅限 QGraphicsItem)
QEvent::GrabMouse 186 项目获得鼠标抓取(仅限 QGraphicsItem)
QEvent::GraphicsSceneContextMenu 159 在图形场景上的上下文弹出菜单(QGraphicsScene ContextMenuEvent)
QEvent::GraphicsSceneDragEnter 164 在拖放操作期间,鼠标进入图形场景(QGraphicsSceneDragDropEvent)
QEvent::GraphicsSceneDragLeave 166 在拖放操作期间鼠标离开图形场景(QGraphicsSceneDragDropEvent)
QEvent::GraphicsSceneDragMove 165 在场景上正在进行拖放操作(QGraphicsSceneDragDropEvent)
QEvent::GraphicsSceneDrop 167 在场景上完成拖放操作(QGraphicsSceneDragDropEvent)
QEvent::GraphicsSceneHelp 163 用户请求图形场景的帮助(QHelpEvent)
QEvent::GraphicsSceneHoverEnter 160 鼠标进入图形场景中的悬停项(QGraphicsSceneHoverEvent)
QEvent::GraphicsSceneHoverLeave 162 鼠标离开图形场景中一个悬停项(QGraphicsSceneHoverEvent)
QEvent::GraphicsSceneHoverMove 161 鼠标在图形场景中的悬停项内移动(QGraphicsSceneHoverEvent)
QEvent::GraphicsSceneMouseDoubleClick 158 鼠标在图形场景中再次按下(双击)(QGraphicsSceneMouseEvent)
QEvent::GraphicsSceneMouseMove 155 鼠标在图形场景中移动(QGraphicsSceneMouseEvent)
QEvent::GraphicsSceneMousePress 156 鼠标在图形场景中按下(QGraphicsSceneMouseEvent)
QEvent::GraphicsSceneMouseRelease 157 鼠标在图形场景中释放(QGraphicsSceneMouseEvent)
QEvent::GraphicsSceneMove 182 部件被移动(QGraphicsSceneMoveEvent)
QEvent::GraphicsSceneResize 181 部件已调整大小(QGraphicsSceneResizeEvent)
QEvent::GraphicsSceneWheel 168 鼠标滚轮在图形场景中滚动(QGraphicsSceneWheelEvent)
QEvent::Hide 18 部件被隐藏(QHideEvent)
QEvent::HideToParent 27 子部件被隐藏(QHideEvent)
QEvent::HoverEnter 127 鼠标进入悬停部件(QHoverEvent)
QEvent::HoverLeave 128 鼠标留离开悬停部件(QHoverEvent)
QEvent::HoverMove 129 鼠标在悬停部件内移动(QHoverEvent)
QEvent::IconDrag 96 窗口的主图标被拖走(QIconDragEvent)
QEvent::IconTextChange 101 部件的图标文本发生改变(已弃用)
QEvent::InputMethod 83 正在使用输入法(QInputMethodEvent)
QEvent::InputMethodQuery 207 输入法查询事件(QInputMethodQueryEvent)
QEvent::KeyboardLayoutChange 169 键盘布局已更改
QEvent::KeyPress 6 键盘按下(QKeyEvent)
QEvent::KeyRelease 7 键盘释放(QKeyEvent)
QEvent::LanguageChange 89 应用程序翻译发生改变
QEvent::LayoutDirectionChange 90 布局的方向发生改变
QEvent::LayoutRequest 76 部件的布局需要重做
QEvent::Leave 11 鼠标离开部件的边界
QEvent::LeaveEditFocus 151 编辑部件失去编辑的焦点,必须定义 QT_KEYPAD_NAVIGATION
QEvent::LeaveWhatsThisMode 125 当应用程序离开“What’s This?”模式,发送到顶层部件
QEvent::LocaleChange 88 系统区域设置发生改变
QEvent::NonClientAreaMouseButtonDblClick 176 鼠标双击发生在客户端区域外
QEvent::NonClientAreaMouseButtonPress 174 鼠标按钮按下发生在客户端区域外
QEvent::NonClientAreaMouseButtonRelease 175 鼠标按钮释放发生在客户端区域外
QEvent::NonClientAreaMouseMove 173 鼠标移动发生在客户区域外
QEvent::MacSizeChange 177 用户更改了部件的大小(仅限 OS X)
QEvent::MetaCall 43 通过 QMetaObject::invokeMethod() 调用异步方法
QEvent::ModifiedChange 102 部件修改状态发生改变
QEvent::MouseButtonDblClick 4 鼠标再次按下(QMouseEvent)
QEvent::MouseButtonPress 2 鼠标按下(QMouseEvent)
QEvent::MouseButtonRelease 3 鼠标释放(QMouseEvent)
QEvent::MouseMove 5 鼠标移动(QMouseEvent)
QEvent::MouseTrackingChange 109 鼠标跟踪状态发生改变
QEvent::Move 13 部件的位置发生改变(QMoveEvent)
QEvent::NativeGesture 197 系统检测到手势(QNativeGestureEvent)
QEvent::OrientationChange 208 屏幕方向发生改变(QScreenOrientationChangeEvent)
QEvent::Paint 12 需要屏幕更新(QPaintEvent)
QEvent::PaletteChange 39 部件的调色板发生改变
QEvent::ParentAboutToChange 131 部件的 parent 将要更改
QEvent::ParentChange 21 部件的 parent 发生改变
QEvent::PlatformPanel 212 请求一个特定于平台的面板
QEvent::PlatformSurface 217 原生平台表面已创建或即将被销毁(QPlatformSurfaceEvent)
QEvent::Polish 75 部件被抛光
QEvent::PolishRequest 74 部件应该被抛光
QEvent::QueryWhatsThis 123 如果部件有“What’s This?”帮助,应该接受事件
QEvent::ReadOnlyChange 106 部件的 read-only 状态发生改变
QEvent::RequestSoftwareInputPanel 199 部件想要打开软件输入面板(SIP)
QEvent::Resize 14 部件的大小发生改变(QResizeEvent)
QEvent::ScrollPrepare 204 对象需要填充它的几何信息(QScrollPrepareEvent)
QEvent::Scroll 205 对象需要滚动到提供的位置(QScrollEvent)
QEvent::Shortcut 117 快捷键处理(QShortcutEvent)
QEvent::ShortcutOverride 51 按下按键,用于覆盖快捷键(QKeyEvent)
QEvent::Show 17 部件显示在屏幕上(QShowEvent)
QEvent::ShowToParent 26 子部件被显示
QEvent::SockAct 50 Socket 激活,用于实现 QSocketNotifier
QEvent::StateMachineSignal 192 信号被传递到状态机(QStateMachine::SignalEvent)
QEvent::StateMachineWrapped 193 事件是一个包装器,用于包含另一个事件(QStateMachine::WrappedEvent)
QEvent::StatusTip 112 状态提示请求(QStatusTipEvent)
QEvent::StyleChange 100 部件的样式发生改变
QEvent::TabletMove 87 Wacom 写字板移动(QTabletEvent)
QEvent::TabletPress 92 Wacom 写字板按下(QTabletEvent)
QEvent::TabletRelease 93 Wacom 写字板释放(QTabletEvent)
QEvent::OkRequest 94 Ok 按钮在装饰前被按下,仅支持 Windows CE
QEvent::TabletEnterProximity 171 Wacom 写字板进入接近事件(QTabletEvent),发送到 QApplication
QEvent::TabletLeaveProximity 172 Wacom 写字板离开接近事件(QTabletEvent),发送到 QApplication
QEvent::ThreadChange 22 对象被移动到另一个线程。这是发送到此对象的最后一个事件在上一个线程中,参见:QObject::moveToThread()
QEvent::Timer 1 定时器事件(QTimerEvent)
QEvent::ToolBarChange 120 工具栏按钮在 OS X 上进行切换
QEvent::ToolTip 110 一个 tooltip 请求(QHelpEvent)
QEvent::ToolTipChange 184 部件的 tooltip 发生改变
QEvent::TouchBegin 194 触摸屏或轨迹板事件序列的开始(QTouchEvent)
QEvent::TouchCancel 209 取消触摸事件序列(QTouchEvent)
QEvent::TouchEnd 196 触摸事件序列结束(QTouchEvent)
QEvent::TouchUpdate 195 触摸屏事件(QTouchEvent)
QEvent::UngrabKeyboard 189 Item 失去键盘抓取(QGraphicsItem)
QEvent::UngrabMouse 187 Item 失去鼠标抓取(QGraphicsItem、QQuickItem)
QEvent::UpdateLater 78 部件应该排队在以后重新绘制
QEvent::UpdateRequest 77 部件应该被重绘
QEvent::WhatsThis 111 部件应该显示“What’s This”帮助(QHelpEvent)
QEvent::WhatsThisClicked 118 部件的“What’s This”帮助链接被点击
QEvent::Wheel 31 鼠标滚轮滚动(QWheelEvent)
QEvent::WinEventAct 132 发生了 Windows 特定的激活事件
QEvent::WindowActivate 24 窗口已激活
QEvent::WindowBlocked 103 窗口被模态对话框阻塞
QEvent::WindowDeactivate 25 窗户被停用
QEvent::WindowIconChange 34 窗口的图标发生改变
QEvent::WindowStateChange 105 窗口的状态(最小化、最大化或全屏)发生改变(QWindowStateChangeEvent)
QEvent::WindowTitleChange 33 窗口的标题发生改变
QEvent::WindowUnblocked 104 一个模态对话框退出后,窗口将不被阻塞
QEvent::WinIdChange 203 本地窗口的系统标识符发生改变
QEvent::ZOrderChange 126 部件的 z 值发生了改变,该事件不会发送给顶层窗口
原文链接:https://blog.csdn.net/liang19890820/article/details/51933153
3. 实例
以较为简单的类型我们去进行一个实验,我们可以在一个event的函数中去对事件的类型进行一个判断,比如是键盘按下的事件,然后我们在这个判断中再去进行对哪个按键的判断,这个的话我们依旧还是在Qt的Assisant中进行查找,博主放在下面供大家参考,大家挑比较常用的看就好~
Qt::Key_Escape 0x01000000 Esc键
Qt::Key_Tab 0x01000001 Tab键
Qt::Key_Backtab 0x01000002 Tab补全键
Qt::Key_Backspace 0x01000003 退格键
Qt::Key_Return 0x01000004 Return键
Qt::Key_Enter 0x01000005 回车键
Qt::Key_Insert 0x01000006 Insert键
Qt::Key_Delete 0x01000007 Delete键
Qt::Key_Pause 0x01000008 暂停键
Qt::Key_Print 0x01000009 截图键
Qt::Key_SysReq 0x0100000a PrtSc
Qt::Key_Clear 0x0100000b 清除键
Qt::Key_Home 0x01000010 Home键
Qt::Key_End 0x01000011 End键
Qt::Key_Left 0x01000012 ←
Qt::Key_Up 0x01000013 ↑
Qt::Key_Right 0x01000014 →
Qt::Key_Down 0x01000015 ↓
Qt::Key_PageUp 0x01000016 上页
Qt::Key_PageDown 0x01000017 下页
Qt::Key_Shift 0x01000020 Shift键
Qt::Key_Control 0x01000021 Ctrl键
Qt::Key_Alt 0x01000023 Alt键
Qt::Key_AltGr 0x01001103 右侧Alt
Qt::Key_CapsLock 0x01000024 大写键
Qt::Key_NumLock 0x01000025 NumLock
Qt::Key_ScrollLock 0x01000026 滚动锁定
Qt::Key_F1 0x01000030 F1~F12
Qt::Key_F2 0x01000031
Qt::Key_F3 0x01000032
Qt::Key_F4 0x01000033
Qt::Key_F5 0x01000034
Qt::Key_F6 0x01000035
Qt::Key_F7 0x01000036
Qt::Key_F8 0x01000037
Qt::Key_F9 0x01000038
Qt::Key_F10 0x01000039
Qt::Key_F11 0x0100003a
Qt::Key_F12 0x0100003b
Qt::Key_Menu 0x01000055 菜单键
Qt::Key_Help 0x01000058 Help键
Qt::Key_Space 0x20 空格键
Qt::Key_Exclam 0x21 !
Qt::Key_QuoteDbl 0x22 引用
Qt::Key_NumberSign 0x23 #
Qt::Key_Dollar 0x24 $
Qt::Key_Percent 0x25 %
Qt::Key_Ampersand 0x26 &
Qt::Key_Apostrophe 0x27 分词符" ' "
Qt::Key_ParenLeft 0x28 (
Qt::Key_ParenRight 0x29 )
Qt::Key_Asterisk 0x2a *
Qt::Key_Plus 0x2b +
Qt::Key_Comma 0x2c ,
Qt::Key_Minus 0x2d -
Qt::Key_Period 0x2e 。
Qt::Key_Slash 0x2f /
Qt::Key_0 0x30 数字0~9
Qt::Key_1 0x31
Qt::Key_2 0x32
Qt::Key_3 0x33
Qt::Key_4 0x34
Qt::Key_5 0x35
Qt::Key_6 0x36
Qt::Key_7 0x37
Qt::Key_8 0x38
Qt::Key_9 0x39
Qt::Key_Colon 0x3a :
Qt::Key_Semicolon 0x3b ;
Qt::Key_Less 0x3c <
Qt::Key_Equal 0x3d 等于
Qt::Key_Greater 0x3e >
Qt::Key_Question 0x3f ?
Qt::Key_At 0x40 @
Qt::Key_A 0x41 字母键
Qt::Key_B 0x42
Qt::Key_C 0x43
Qt::Key_D 0x44
Qt::Key_E 0x45
Qt::Key_F 0x46
Qt::Key_G 0x47
Qt::Key_H 0x48
Qt::Key_I 0x49
Qt::Key_J 0x4a
Qt::Key_K 0x4b
Qt::Key_L 0x4c
Qt::Key_M 0x4d
Qt::Key_N 0x4e
Qt::Key_O 0x4f
Qt::Key_P 0x50
Qt::Key_Q 0x51
Qt::Key_R 0x52
Qt::Key_S 0x53
Qt::Key_T 0x54
Qt::Key_U 0x55
Qt::Key_V 0x56
Qt::Key_W 0x57
Qt::Key_X 0x58
Qt::Key_Y 0x59
Qt::Key_Z 0x5a
Qt::Key_BracketLeft 0x5b [
Qt::Key_Backslash 0x5c \
Qt::Key_BracketRight 0x5d ]
Qt::Key_AsciiCircum 0x5e ^
Qt::Key_Underscore 0x5f _
Qt::Key_QuoteLeft 0x60 “
Qt::Key_BraceLeft 0x7b {
Qt::Key_Bar 0x7c |
Qt::Key_BraceRight 0x7d }
Qt::Key_AsciiTilde 0x7e ~
Qt::Key_nobreakspace 0x0a0 不换行空格
Qt::Key_exclamdown 0x0a1 !
Qt::Key_cent 0x0a2 美分
Qt::Key_sterling 0x0a3 英镑
Qt::Key_currency 0x0a4 货币
Qt::Key_yen 0x0a5 日元
Qt::Key_brokenbar 0x0a6
Qt::Key_section 0x0a7
Qt::Key_diaeresis 0x0a8
Qt::Key_copyright 0x0a9
Qt::Key_ordfeminine 0x0aa
Qt::Key_guillemotleft 0x0ab
Qt::Key_notsign 0x0ac
Qt::Key_hyphen 0x0ad
Qt::Key_registered 0x0ae
Qt::Key_macron 0x0af
Qt::Key_degree 0x0b0
Qt::Key_plusminus 0x0b1
Qt::Key_twosuperior 0x0b2
Qt::Key_threesuperior 0x0b3
Qt::Key_acute 0x0b4
Qt::Key_mu 0x0b5
Qt::Key_paragraph 0x0b6
Qt::Key_periodcentered 0x0b7
Qt::Key_cedilla 0x0b8
Qt::Key_onesuperior 0x0b9
Qt::Key_masculine 0x0ba
Qt::Key_guillemotright 0x0bb
Qt::Key_onequarter 0x0bc
Qt::Key_onehalf 0x0bd
Qt::Key_threequarters 0x0be
Qt::Key_questiondown 0x0bf
Qt::Key_Agrave 0x0c0
Qt::Key_Aacute 0x0c1
Qt::Key_Acircumflex 0x0c2
Qt::Key_Atilde 0x0c3
Qt::Key_Adiaeresis 0x0c4
Qt::Key_Aring 0x0c5
Qt::Key_AE 0x0c6
Qt::Key_Ccedilla 0x0c7
Qt::Key_Egrave 0x0c8
Qt::Key_Eacute 0x0c9
Qt::Key_Ecircumflex 0x0ca
Qt::Key_Ediaeresis 0x0cb
Qt::Key_Igrave 0x0cc
Qt::Key_Iacute 0x0cd
Qt::Key_Icircumflex 0x0ce
Qt::Key_Idiaeresis 0x0cf
Qt::Key_ETH 0x0d0
Qt::Key_Ntilde 0x0d1
Qt::Key_Ograve 0x0d2
Qt::Key_Oacute 0x0d3
Qt::Key_Ocircumflex 0x0d4
Qt::Key_Otilde 0x0d5
Qt::Key_Odiaeresis 0x0d6
Qt::Key_multiply 0x0d7
Qt::Key_Ooblique 0x0d8
Qt::Key_Ugrave 0x0d9
Qt::Key_Uacute 0x0da
Qt::Key_Ucircumflex 0x0db
Qt::Key_Udiaeresis 0x0dc
Qt::Key_Yacute 0x0dd
Qt::Key_THORN 0x0de
Qt::Key_ssharp 0x0df
Qt::Key_division 0x0f7
Qt::Key_ydiaeresis 0x0ff
Qt::Key_Multi_key 0x01001120
Qt::Key_Codeinput 0x01001137
Qt::Key_SingleCandidate 0x0100113c
Qt::Key_MultipleCandidate 0x0100113d
Qt::Key_PreviousCandidate 0x0100113e
Qt::Key_Mode_switch 0x0100117e
Qt::Key_Kanji 0x01001121
Qt::Key_Muhenkan 0x01001122
Qt::Key_Henkan 0x01001123
Qt::Key_Romaji 0x01001124
Qt::Key_Hiragana 0x01001125
Qt::Key_Katakana 0x01001126
Qt::Key_Hiragana_Katakana 0x01001127
Qt::Key_Zenkaku 0x01001128
Qt::Key_Hankaku 0x01001129
Qt::Key_Zenkaku_Hankaku 0x0100112a
Qt::Key_Touroku 0x0100112b
Qt::Key_Massyo 0x0100112c
Qt::Key_Kana_Lock 0x0100112d
Qt::Key_Kana_Shift 0x0100112e
Qt::Key_Eisu_Shift 0x0100112f
Qt::Key_Eisu_toggle 0x01001130
Qt::Key_Hangul 0x01001131
Qt::Key_Hangul_Start 0x01001132
Qt::Key_Hangul_End 0x01001133
Qt::Key_Hangul_Hanja 0x01001134
Qt::Key_Hangul_Jamo 0x01001135
Qt::Key_Hangul_Romaja 0x01001136
Qt::Key_Hangul_Jeonja 0x01001138
Qt::Key_Hangul_Banja 0x01001139
Qt::Key_Hangul_PreHanja 0x0100113a
Qt::Key_Hangul_PostHanja 0x0100113b
Qt::Key_Hangul_Special 0x0100113f
Qt::Key_Dead_Grave 0x01001250
Qt::Key_Dead_Acute 0x01001251
Qt::Key_Dead_Circumflex 0x01001252
Qt::Key_Dead_Tilde 0x01001253
Qt::Key_Dead_Macron 0x01001254
Qt::Key_Dead_Breve 0x01001255
Qt::Key_Dead_Abovedot 0x01001256
Qt::Key_Dead_Diaeresis 0x01001257
Qt::Key_Dead_Abovering 0x01001258
Qt::Key_Dead_Doubleacute 0x01001259
Qt::Key_Dead_Caron 0x0100125a
Qt::Key_Dead_Cedilla 0x0100125b
Qt::Key_Dead_Ogonek 0x0100125c
Qt::Key_Dead_Iota 0x0100125d
Qt::Key_Dead_Voiced_Sound 0x0100125e
Qt::Key_Dead_Semivoiced_Sound 0x0100125f
Qt::Key_Dead_Belowdot 0x01001260
Qt::Key_Dead_Hook 0x01001261
Qt::Key_Dead_Horn 0x01001262
Qt::Key_Dead_Stroke 0x01001263
Qt::Key_Dead_Abovecomma 0x01001264
Qt::Key_Dead_Abovereversedcomma 0x01001265
Qt::Key_Dead_Doublegrave 0x01001266
Qt::Key_Dead_Belowring 0x01001267
Qt::Key_Dead_Belowmacron 0x01001268
Qt::Key_Dead_Belowcircumflex 0x01001269
Qt::Key_Dead_Belowtilde 0x0100126a
Qt::Key_Dead_Belowbreve 0x0100126b
Qt::Key_Dead_Belowdiaeresis 0x0100126c
Qt::Key_Dead_Invertedbreve 0x0100126d
Qt::Key_Dead_Belowcomma 0x0100126e
Qt::Key_Dead_Currency 0x0100126f
Qt::Key_Dead_a 0x01001280
Qt::Key_Dead_A 0x01001281
Qt::Key_Dead_e 0x01001282
Qt::Key_Dead_E 0x01001283
Qt::Key_Dead_i 0x01001284
Qt::Key_Dead_I 0x01001285
Qt::Key_Dead_o 0x01001286
Qt::Key_Dead_O 0x01001287
Qt::Key_Dead_u 0x01001288
Qt::Key_Dead_U 0x01001289
Qt::Key_Dead_Small_Schwa 0x0100128a
Qt::Key_Dead_Capital_Schwa 0x0100128b
Qt::Key_Dead_Greek 0x0100128c
Qt::Key_Dead_Lowline 0x01001290
Qt::Key_Dead_Aboveverticalline 0x01001291
Qt::Key_Dead_Belowverticalline 0x01001292
Qt::Key_Dead_Longsolidusoverlay 0x01001293
Qt::Key_Back 0x01000061
Qt::Key_Forward 0x01000062
Qt::Key_Stop 0x01000063
Qt::Key_Refresh 0x01000064
Qt::Key_VolumeDown 0x01000070
Qt::Key_VolumeMute 0x01000071
Qt::Key_VolumeUp 0x01000072
Qt::Key_BassBoost 0x01000073
Qt::Key_BassUp 0x01000074
Qt::Key_BassDown 0x01000075
Qt::Key_TrebleUp 0x01000076
Qt::Key_TrebleDown 0x01000077
Qt::Key_MediaPlay 0x01000080 A key setting the state of the media player to play
Qt::Key_MediaStop 0x01000081 A key setting the state of the media player to stop
Qt::Key_MediaPrevious 0x01000082
Qt::Key_MediaNext 0x01000083
Qt::Key_MediaRecord 0x01000084
Qt::Key_MediaPause 0x1000085 A key setting the state of the media player to pause (Note: not the pause/break key)
Qt::Key_MediaTogglePlayPause 0x1000086 A key to toggle the play/pause state in the media player (rather than setting an absolute state)
Qt::Key_HomePage 0x01000090
Qt::Key_Favorites 0x01000091
Qt::Key_Search 0x01000092
Qt::Key_Standby 0x01000093
Qt::Key_OpenUrl 0x01000094
Qt::Key_LaunchMail 0x010000a0
Qt::Key_LaunchMedia 0x010000a1
Qt::Key_Launch0 0x010000a2 On X11 this key is mapped to "My Computer" (XF86XK_MyComputer) key for legacy reasons.
Qt::Key_Launch1 0x010000a3 On X11 this key is mapped to "Calculator" (XF86XK_Calculator) key for legacy reasons.
Qt::Key_Launch2 0x010000a4 On X11 this key is mapped to XF86XK_Launch0 key for legacy reasons.
Qt::Key_Launch3 0x010000a5 On X11 this key is mapped to XF86XK_Launch1 key for legacy reasons.
Qt::Key_Launch4 0x010000a6 On X11 this key is mapped to XF86XK_Launch2 key for legacy reasons.
Qt::Key_Launch5 0x010000a7 On X11 this key is mapped to XF86XK_Launch3 key for legacy reasons.
Qt::Key_Launch6 0x010000a8 On X11 this key is mapped to XF86XK_Launch4 key for legacy reasons.
Qt::Key_Launch7 0x010000a9 On X11 this key is mapped to XF86XK_Launch5 key for legacy reasons.
Qt::Key_Launch8 0x010000aa On X11 this key is mapped to XF86XK_Launch6 key for legacy reasons.
Qt::Key_Launch9 0x010000ab On X11 this key is mapped to XF86XK_Launch7 key for legacy reasons.
Qt::Key_LaunchA 0x010000ac On X11 this key is mapped to XF86XK_Launch8 key for legacy reasons.
Qt::Key_LaunchB 0x010000ad On X11 this key is mapped to XF86XK_Launch9 key for legacy reasons.
Qt::Key_LaunchC 0x010000ae On X11 this key is mapped to XF86XK_LaunchA key for legacy reasons.
Qt::Key_LaunchD 0x010000af On X11 this key is mapped to XF86XK_LaunchB key for legacy reasons.
Qt::Key_LaunchE 0x010000b0 On X11 this key is mapped to XF86XK_LaunchC key for legacy reasons.
Qt::Key_LaunchF 0x010000b1 On X11 this key is mapped to XF86XK_LaunchD key for legacy reasons.
Qt::Key_LaunchG 0x0100010e On X11 this key is mapped to XF86XK_LaunchE key for legacy reasons.
Qt::Key_LaunchH 0x0100010f On X11 this key is mapped to XF86XK_LaunchF key for legacy reasons.
Qt::Key_MonBrightnessUp 0x010000b2
Qt::Key_MonBrightnessDown 0x010000b3
Qt::Key_KeyboardLightOnOff 0x010000b4
Qt::Key_KeyboardBrightnessUp 0x010000b5
Qt::Key_KeyboardBrightnessDown 0x010000b6
Qt::Key_PowerOff 0x010000b7
Qt::Key_WakeUp 0x010000b8
Qt::Key_Eject 0x010000b9
Qt::Key_ScreenSaver 0x010000ba
Qt::Key_WWW 0x010000bb
Qt::Key_Memo 0x010000bc
Qt::Key_LightBulb 0x010000bd
Qt::Key_Shop 0x010000be
Qt::Key_History 0x010000bf
Qt::Key_AddFavorite 0x010000c0
Qt::Key_HotLinks 0x010000c1
Qt::Key_BrightnessAdjust 0x010000c2
Qt::Key_Finance 0x010000c3
Qt::Key_Community 0x010000c4
Qt::Key_AudioRewind 0x010000c5
Qt::Key_BackForward 0x010000c6
Qt::Key_ApplicationLeft 0x010000c7
Qt::Key_ApplicationRight 0x010000c8
Qt::Key_Book 0x010000c9
Qt::Key_CD 0x010000ca
Qt::Key_Calculator 0x010000cb On X11 this key is not mapped for legacy reasons. Use Qt::Key_Launch1 instead.
Qt::Key_ToDoList 0x010000cc
Qt::Key_ClearGrab 0x010000cd
Qt::Key_Close 0x010000ce
Qt::Key_Copy 0x010000cf
Qt::Key_Cut 0x010000d0
Qt::Key_Display 0x010000d1
Qt::Key_DOS 0x010000d2
Qt::Key_Documents 0x010000d3
Qt::Key_Excel 0x010000d4
Qt::Key_Explorer 0x010000d5
Qt::Key_Game 0x010000d6
Qt::Key_Go 0x010000d7
Qt::Key_iTouch 0x010000d8
Qt::Key_LogOff 0x010000d9
Qt::Key_Market 0x010000da
Qt::Key_Meeting 0x010000db
Qt::Key_MenuKB 0x010000dc
Qt::Key_MenuPB 0x010000dd
Qt::Key_MySites 0x010000de
Qt::Key_News 0x010000df
Qt::Key_OfficeHome 0x010000e0
Qt::Key_Option 0x010000e1
Qt::Key_Paste 0x010000e2
Qt::Key_Phone 0x010000e3
Qt::Key_Calendar 0x010000e4
Qt::Key_Reply 0x010000e5
Qt::Key_Reload 0x010000e6
Qt::Key_RotateWindows 0x010000e7
Qt::Key_RotationPB 0x010000e8
Qt::Key_RotationKB 0x010000e9
Qt::Key_Save 0x010000ea
Qt::Key_Send 0x010000eb
Qt::Key_Spell 0x010000ec
Qt::Key_SplitScreen 0x010000ed
Qt::Key_Support 0x010000ee
Qt::Key_TaskPane 0x010000ef
Qt::Key_Terminal 0x010000f0
Qt::Key_Tools 0x010000f1
Qt::Key_Travel 0x010000f2
Qt::Key_Video 0x010000f3
Qt::Key_Word 0x010000f4
Qt::Key_Xfer 0x010000f5
Qt::Key_ZoomIn 0x010000f6
Qt::Key_ZoomOut 0x010000f7
Qt::Key_Away 0x010000f8
Qt::Key_Messenger 0x010000f9
Qt::Key_WebCam 0x010000fa
Qt::Key_MailForward 0x010000fb
Qt::Key_Pictures 0x010000fc
Qt::Key_Music 0x010000fd
Qt::Key_Battery 0x010000fe
Qt::Key_Bluetooth 0x010000ff
Qt::Key_WLAN 0x01000100
Qt::Key_UWB 0x01000101
Qt::Key_AudioForward 0x01000102
Qt::Key_AudioRepeat 0x01000103
Qt::Key_AudioRandomPlay 0x01000104
Qt::Key_Subtitle 0x01000105
Qt::Key_AudioCycleTrack 0x01000106
Qt::Key_Time 0x01000107
Qt::Key_Hibernate 0x01000108
Qt::Key_View 0x01000109
Qt::Key_TopMenu 0x0100010a
Qt::Key_PowerDown 0x0100010b
Qt::Key_Suspend 0x0100010c
Qt::Key_ContrastAdjust 0x0100010d
Qt::Key_TouchpadToggle 0x01000110
Qt::Key_TouchpadOn 0x01000111
Qt::Key_TouchpadOff 0x01000112
Qt::Key_MicMute 0x01000113
Qt::Key_Red 0x01000114
Qt::Key_Green 0x01000115
Qt::Key_Yellow 0x01000116
Qt::Key_Blue 0x01000117
Qt::Key_ChannelUp 0x01000118
Qt::Key_ChannelDown 0x01000119
Qt::Key_Guide 0x0100011a
Qt::Key_Info 0x0100011b
Qt::Key_Settings 0x0100011c
Qt::Key_MicVolumeUp 0x0100011d
Qt::Key_MicVolumeDown 0x0100011e
Qt::Key_New 0x01000120
Qt::Key_Open 0x01000121
Qt::Key_Find 0x01000122
Qt::Key_Undo 0x01000123
Qt::Key_Redo 0x01000124
Qt::Key_MediaLast 0x0100ffff
Qt::Key_unknown 0x01ffffff
Qt::Key_Call 0x01100004 A key to answer or initiate a call (see Qt::Key_ToggleCallHangup for a key to toggle current call state)
Qt::Key_Camera 0x01100020 A key to activate the camera shutter. On Windows Runtime, the environment variable QT_QPA_ENABLE_CAMERA_KEYS must be set to receive the event.
Qt::Key_CameraFocus 0x01100021 A key to focus the camera. On Windows Runtime, the environment variable QT_QPA_ENABLE_CAMERA_KEYS must be set to receive the event.
Qt::Key_Context1 0x01100000
Qt::Key_Context2 0x01100001
Qt::Key_Context3 0x01100002
Qt::Key_Context4 0x01100003
Qt::Key_Flip 0x01100006
Qt::Key_Hangup 0x01100005 A key to end an ongoing call (see Qt::Key_ToggleCallHangup for a key to toggle current call state)
Qt::Key_No 0x01010002
Qt::Key_Select 0x01010000
Qt::Key_Yes 0x01010001
Qt::Key_ToggleCallHangup 0x01100007 A key to toggle the current call state (ie. either answer, or hangup) depending on current call state
Qt::Key_VoiceDial 0x01100008
Qt::Key_LastNumberRedial 0x01100009
Qt::Key_Execute 0x01020003
Qt::Key_Printer 0x01020002
Qt::Key_Play 0x01020005
Qt::Key_Sleep 0x01020004
Qt::Key_Zoom 0x01020006
Qt::Key_Exit 0x0102000a
Qt::Key_Cancel 0x01020001
进行一个简单的判断,代码如下:
bool myWidget::event(QEvent *e)
{
if (e->type() == QEvent::KeyPress)
{
//将QEvent对象转换为真正的QKeyEvent对象
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e);
if (keyEvent->key() == Qt::Key_Escape )
{
qDebug() << "Windows exit";
return true;
}
}
}
我们也可以用Qt自带的keyPressEvent进行写函数,这种也会更加方便一些。文章来源:https://www.toymoban.com/news/detail-830955.html
void MainWindow::keyPressEvent(QKeyEvent *event)
{
if(event->key() == Qt::Key_Escape)
{
qDebug() << "Windows exit";
return true;
}
}
当然还有其他很多的类型,大家如果有需要可以自行查找在表中,希望可以帮到大家!!文章来源地址https://www.toymoban.com/news/detail-830955.html
到了这里,关于Qt中的事件该如何学习?(附带案例)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!