[Qt-interest] mouse buttons

Erik Kruyt erik at forcheck.nl
Mon Mar 22 18:30:30 CET 2010


I want to react differently on a right, left and double mouse button click
in a QTreeWidget.

QTreeWidget only provides an itemClicked and an itemDoubleclicked signal.

How can I detect if the itemclicked signal was caused by the right or a left
mouse button?

 

The documentation of QTreeWidget does not give an answer.

The documentation of QAbstractItemView::pressed states that you can obtain
the state of the mouse buttons through QApplication::mouseButtons(). This is
a static function. I tried this but no buttons are reported to be pressed!

Example of the slot receiving the itemClicked signal:

 

void ProjectFrame::itemClicked(QTreeWidgetItem *item, int column)

{

    if (column == 0){

        itemSelected(item);

        Qt::MouseButtons buttons = QApplication::mouseButtons();

        if (buttons.testFlag(Qt::RightButton)){

            popUpMenu->exec(QCursor::pos());

        }

    }

}

 

As an alternative I tried to reïmplement mousePressEvent. Now I can
discriminate between right and left button. However, now I cannot
discriminate the double mouse click, because the double click starts the
mouseClickEvent instead of the mouseDoubleClickEvent! Moreover, now I have
to implement the item selection and deselections anew.

 

So the question is: how can I retrieve the mousebutton clicked in the
itemClicked signal?

 

Erik Kruyt

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100322/e5f32953/attachment.html 


More information about the Qt-interest-old mailing list