qt 键盘按键事件 范例 keyPreEvent()
2010-07-20 17:13
1591 查看
CompleteLineEdit::keyPressEvent(QKeyEvent *e) {
if (!listView->isHidden()) {
int key = e->key();
int count = listView->model()->rowCount();
QModelIndex currentIndex = listView->currentIndex();
if (Qt::Key_Down == key) {
// 按向下方向键时,移动光标选中下一个完成列表中的项
int row = currentIndex.row() + 1;
if (row >= count) {
row = 0;
}
QModelIndex index = listView->model()->index(row, 0);
listView->setCurrentIndex(index);
} else if (Qt::Key_Up == key) {
// 按向下方向键时,移动光标选中上一个完成列表中的项
int row = currentIndex.row() - 1;
if (row < 0) {
row = count - 1;
}
QModelIndex index = listView->model()->index(row, 0);
listView->setCurrentIndex(index);
} else if (Qt::Key_Escape == key) {
// 按下Esc键时,隐藏完成列表
listView->hide();
} else if (Qt::Key_Enter == key || Qt::Key_Return == key) {
// 按下回车键时,使用完成列表中选中的项,并隐藏完成列表
if (currentIndex.isValid()) {
QString text = listView->currentIndex().data().toString();
setText(text);
}
listView->hide();
} else {
// 其他情况,隐藏完成列表,并使用QLineEdit的键盘按下事件
listView->hide();
QLineEdit::keyPressEvent(e);
}
} else {
QLineEdit::keyPressEvent(e);
}
相关文章推荐
- java.awt.event.KeyEvent(键盘按键对应的KeyCode)
- 详细解析JavaFX的键盘事件KeyEvent - Pressd/Released/Typed
- #636 – 持续按住按键会多次触发键盘事件(Keyboard Events that Fire When A Key Is Held Down)
- Qt 处理键盘按键事件:只能输入字母 keyPressEvent
- C#窗体如何通过keybd_event()函数模拟键盘按键(组合键)产生事件
- Qt获取键盘按键事件(Windows API)----StateReader系列
- 利用键盘事件keybd_event(Win32 API)模拟键盘按键
- 从keyPressEvent按键事件中获取QKeySequence
- (浏览器兼容)键盘事件兼容写法e=window.event||e;键盘检测兼容写法key = e.keyCode || e.which || e.charCode;
- qt学习之键盘事件( keyPressEvent)
- Qt使用Windows Api模拟键盘事件,附Qt::key转windows键值
- QT事件处理,鼠标事件,按键键盘事件,定时器,进度条。
- Qt setMouseTracking设置处了但是不按键也不能触发mouseMoveEvent()事件
- JS 获取键盘按键 event.altKey、event.ctrlKey、event.shiftKey 属性
- 【Android TV】按键事件KeyEvent的分发处理流程解析
- Qt中使用事件过滤器来处理键盘焦点
- 源码-JavaScript&jQuery交互式前端开发-第6章-事件-键盘事件-确定按键值
- Redis 事件通知(keyspace & keyevent notification)
- 【Android】代码实现模拟屏幕点击和键盘按键事件
- keybd_event,mouse_event 模拟产生键盘事件、鼠标事件的使用