[Qt-interest] mouse buttons

Dan White ygor at comcast.net
Mon Mar 22 21:26:52 CET 2010


It says here <http://doc.trolltech.com/4.6/qmouseevent.html#details>

"Reimplement the QWidget event handlers, QWidget::mousePressEvent(), QWidget::mouseReleaseEvent(), QWidget::mouseDoubleClickEvent(), and QWidget::mouseMoveEvent() to receive mouse events in your own widgets."

and it says here <http://doc.trolltech.com/4.6/qevent.html#Type-enum> that there is such a thing as a 
QEvent::MouseButtonDblClick as well as a QEvent::MouseButtonPress

So your handler needs to handle them both.

“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 did try the mousePressEvent handler, see below!
> 
> > -----Oorspronkelijk bericht-----
> > Van: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> > bounces at trolltech.com] Namens Dan White
> > Verzonden: maandag 22 maart 2010 18:59
> > Aan: qt-interest at trolltech.com
> > Onderwerp: Re: [Qt-interest] mouse buttons
> > 
> > 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
> > >
> > 
> > 
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
> 
> 





More information about the Qt-interest-old mailing list