[Qt-interest] mouse buttons

Ramesh ramesh.bs at robosoftin.com
Tue Mar 23 07:44:41 CET 2010


You try installing the event-filter and handle there..

I think this could work

 

From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of Erik Kruyt
Sent: Monday, March 22, 2010 11:01 PM
To: qt-interest at trolltech.com
Subject: [Qt-interest] mouse buttons

 

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


-----------------------------------------------
Robosoft Technologies - Come home to Technology

Disclaimer: This email may contain confidential material. If you were not an intended recipient, please notify the sender and delete all copies. Emails to and from our network may be logged and monitored. This email and its attachments are scanned for virus by our scanners and are believed to be safe. However, no warranty is given that this email is free of malicious content or virus.

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


More information about the Qt-interest-old mailing list