Qt::QTableWidget: SIGNAL currentCellChanged:鼠标和键盘之间的差异
Qt::QTableWidget: SIGNAL currentCellChanged: Differ between mouse and keyboard
我有一个QTableWidget,每当我用鼠标或键盘(制表键或箭头键)选择一行时,它都会发出调用SLOT方法的SIGNAL currentCellChanged。是否有可能找出使用的是哪一个(鼠标还是键盘)?
我假设您使用的是一个普通的Designer表单类,表格小部件是该表单的一部分。
在你的表单类的构造函数中,你应该这样做:
ui->tableWidget->viewport()->installEventFilter(this);
添加eventFilter
方法到你的类(它重新实现虚拟的QObject::eventFilter
):
bool MyForm::eventFilter(QObject* object, QEvent* event) {
if (object == ui->tableWidget->viewport()) {
if (event->type() == QEvent::KeyPress) {
method = method_keyboard;
} else if (event->type() == QEvent::MouseButtonPress) {
method = method_mouse;
}
}
return false;
}
在槽中,您可以查看method
变量的值,以确定使用了哪个控件。
相关文章:
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- int(c) 和 c-'0' 之间的区别。C++
- 物理键盘上的触发器按键
- 在cuda线程之间共享大量常量数据
- 如何使用C/C++在MacOSX中获得键盘布局
- 在c代码之间共享数据的最佳方式
- Mix_Init和Mix_OpenAudio SDL之间的区别是什么
- C++ 使用 assign 函数的字符串与直接使用 '=' 更改值的字符串之间的区别
- VSOMEIP-2个设备之间的通信(TCP/UDP)不工作
- std::atomic和std::condition_variable wait,notify_*方法之间的区别
- 大小相等但成员数量不同的结构之间的性能差异
- 类与私有变量的其他类之间的线程安全性
- 如何在cpp文件之间切换窗口?在Qt中
- 线程之间的布尔停止信号
- 我是C++编程的新手,这些代码之间有什么区别,我应该使用哪一个
- 在 const 函数中通过引用和指针返回之间的区别
- 我想知道长双倍和双倍之间的区别
- 如何防止clang格式在流运算符调用之间添加换行符<<
- 管理Win32应用程序和QWinMigrate之间的键盘事件
- Qt::QTableWidget: SIGNAL currentCellChanged:鼠标和键盘之间的差异