Qt双击检查鼠标左键 [英] Qt double click check left button mouse
本文介绍了Qt双击检查鼠标左键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要运行slot只在doubleClick上用鼠标左键,而不是两者。
I need to run slot only on doubleClick with left button mouse, instead of both.
// this->myComponent is a QTableView
connect(this -> myComponent, SIGNAL (doubleClicked (const QModelIndex & )), this,
SLOT (performSomeAction(const QModelIndex & )));
在这种情况下,双击工作在这两种情况,但只需要左键点击。
我该怎么办?
With this event, double click works in both cases, but needed only with left button click. How I can do it?
this -> myComponent => QTableView
推荐答案
我找到了以下解决方案:
I found the following solution:
this -> myComponent -> viewport() -> installEventFilter(this);
bool MyClass::eventFilter(QObject *obj, QEvent *event) {
this -> event = event;
return QWidget::eventFilter(obj, event);
}
...
if (this -> event -> type() == QEvent::MouseButtonDblClick) {
QMouseEvent * mouseEvent = static_cast <QMouseEvent *> (event);
if (mouseEvent -> button() == Qt::LeftButton) {
// do something....
}
}
这篇关于Qt双击检查鼠标左键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文