我不認爲這是一個非常可能的方案,但它可能發生。
一個「簡單」的辦法,以確保有關所單擊按鈕是子類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