[Qt-interest] mouse buttons

Dan White ygor at comcast.net
Mon Mar 22 18:58:31 CET 2010


I think I have a better pointer:

What you want should, I believe, be handled in the mousePressEvent handler (inherited from QTreeView)

<http://doc.trolltech.com/4.6/qtreeview.html#mousePressEvent>

<http://doc.trolltech.com/4.6/eventsandfilters.html>

Good luck.

“Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.”
Bill Waterson (Calvin & Hobbes)

----- Erik Kruyt <erik at forcheck.nl> wrote:
> 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
> 





More information about the Qt-interest-old mailing list