我不认为这是一个非常可能的方案,但它可能发生。
一个“简单”的办法,以确保有关所单击按钮是子类QTableView
(或者你正在使用的视图,并重新实现mouseReleaseEvent
。
void mouseReleaseEvent(QMouseEvent * event)
{
// store the button that was clicked
mButton = event->button();
// Now call the parent's event
QTableView::mouseReleaseEvent(event);
}
默认情况下,mouseReleaseEvent
发出clicked
信号如果视图的项目按
如果用户按下鼠标小部件内,然后松开鼠标按钮之前,拖动鼠标 到另一个位置,您 小部件接收发布事件。如果正在按下某个项目,该功能将发出 clicked()信号。
诀窍是捕捉clicked
信号中派生类和发射一个新的信号,该信号除模型索引将包含按钮,以及。
// Define your new signal in the header
signals:
void clicked(QModelIndex, Qt::MouseButton);
// and a slot that will emit it
private slots:
void clickedSlot(QModelIndex);
// In the constructor of your derived class connect the default clicked with a slot
connect(this, SIGNAL(clicked(QModelIndex), this, SLOT(clickedSlot(QModelIndex)));
// Now the slot just emits the new clicked signal with the button that was pressed
void clickedSlot(QModelIndex i)
{
emit clicked(i, mButton);
}
如果你需要pressed
信号,以及你可以做的mousePressEvent
类似的东西。
谢谢你 - 这是真正真正的辉煌。我现在可以放弃使用QApplication :: mouseButtons。 –
欢迎... – pnezis