[Qt-interest] mouse buttons

Erik Kruyt erik at forcheck.nl
Wed Mar 24 13:31:32 CET 2010


I implemented a local event handler to catch all events.
The event QEvent::MouseButtonDblClick did not show up when double clicking!

> -----Oorspronkelijk bericht-----
> Van: Zaid Amir [mailto:z.alamir at genie-soft.com]
> Verzonden: dinsdag 23 maart 2010 14:30
> Aan: 'Frederic Tingaud'; 'Erik Kruyt'
> CC: qt-interest at trolltech.com
> Onderwerp: RE: [Qt-interest] mouse buttons
> 
> Have you tried installing an event filter. It would filter any event
> related
> to the QObject that you install it to. You should check the QT
> documentation
> on how to implement an eventFilter.
> 
> Regards
> 
> -----Original Message-----
> From: Frederic Tingaud [mailto:tingaud at gostai.com]
> Sent: Tuesday, March 23, 2010 2:41 PM
> To: Erik Kruyt
> Cc: z.alamir at genie-soft.com; qt-interest at trolltech.com
> Subject: Re: [Qt-interest] mouse buttons
> 
> Erik Kruyt a écrit :
> > This is just what I tried and described in the first place (at the
> bottom).
> >
> > For a mouse click or enter the mousePressEvent method is invoked and
> I can
> > discriminate between left and right button correctly.
> >
> > However, the mouseDoubleClickEvent method is not entered when double
> > clicked. At double clicking the mousePressEvent method is invoked and
> not
> > the mouseDoubleClickEvent. I don't see how I know it was a double
> click.
> The
> > event is QMouseEvent and the button is Qt::LeftButton.
> >
> > The documentation is a mystery for me:
> >
> =======================================================================
> =====
> > ======
> > void QWidget::mouseDoubleClickEvent (QMouseEvent * event)   [virtual
> > protected]
> > This event handler, for event event, can be reimplemented in a
> subclass to
> > receive mouse double click events for the widget.
> >
> > The default implementation generates a normal mouse press event.
> ?????
> >
> > Note: The widget will also receive mouse press and mouse release
> events in
> > addition to the double click event. It is up to the developer to
> ensure
> that
> > the application interprets these events correctly.  ?????
> >
> > See also mousePressEvent(), mouseReleaseEvent(), mouseMoveEvent(),
> event(),
> > and QMouseEvent.
> >
> =======================================================================
> =====
> > =====
> >
> > So the problem remains: how do I catch the double click?.
> >
> > Erik
> >
> >
> >> -----Oorspronkelijk bericht-----
> >> Van: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> >> bounces at trolltech.com] Namens Zaid Amir
> >> Verzonden: dinsdag 23 maart 2010 8:07
> >> Aan: qt-interest at trolltech.com
> >> Onderwerp: Re: [Qt-interest] mouse buttons
> >>
> >> Hi
> >>
> >> To monitor mouse events you could use the mousePressEvent,
> >> mouseReleaseEvent
> >> and mouseMoveEvent which are virtual functions that, when
> implemented
> >> in
> >> your class, immediately capture all the desired mouse events so that
> >> you can
> >> do whatever you want with them. You can filter the event even more
> by
> >> specifying different functionality for left, middle and right-click
> >> events.
> >> You could do this by checking the type of the QMouseEvent as such:
> >>
> >> mousePressEvent ( QMouseEvent * event )
> >> {
> >> 	If(event->button() == Qt::MouseButton::LeftButton)
> >> 		//Do something
> >> 	Else if (event->button() == Qt::MouseButton::RightButton)
> >> 		//Do Something Different
> >>
> >> }
> >>
> >>
> >> And since QTreeWidget is actually a QObject you could install and
> event
> >> filter for that item. Check the part for eventFilter in the
> >> documentation
> >> for details and examples on how to use and install an event filter.
> >>
> >> Regards
> >>
> >> Zaid Amir
> >>
> >> Date: Mon, 22 Mar 2010 18:30:30 +0100
> >> From: "Erik Kruyt" <erik at forcheck.nl>
> >> Subject: [Qt-interest] mouse buttons
> >> To: <qt-interest at trolltech.com>
> >> Message-ID: <009f01cac9e5$5edd5de0$1c9819a0$@nl>
> >> Content-Type: text/plain; charset="iso-8859-1"
> >>
> >> 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
> >>
> >
> >
> >
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
> >
> If you don't have the double click events, is it not because you forgot
> to pass the event to QTreeWidget::mousePressEvent() at the end of your
> ProjectFrame::mousePressEvent() ?
> 
> Otherwise, you need to use a timer when entering mousePressEvent and
> compare result to qApp->doubleClickInterval.
> 
> --
> -----------------------------------------------------------------------
> -----
> ---
> Frederic TINGAUD
> 
> -----------------------------------------------------------------------
> -----
> ---
> 
> 
> 







More information about the Qt-interest-old mailing list