Results 1 to 9 of 9

Thread: Qt5 - mouseDoubleClickEvent

  1. #1
    Join Date
    Jan 2009
    Location
    Midlands UK
    Posts
    62
    Thanks
    6
    Thanked 9 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Qt5 - mouseDoubleClickEvent

    Hi all,

    I'm porting a number of progs from Qt4 to Qt5 on mswindows and cannot get the mouse double click event to fire on qt5.

    I setup a simple mainwindow widget with an event catcher:

    bool MainWindow::event(QEvent *event)
    {
    if((event->type() >= 2) && (event->type() <= 5))
    qDebug() << (int)event->type() ;
    }

    but it only lists press, release, press, release type codes for double clicks. I've tried it on XP and Win7 - both same result

    I've noticed on various forums chatter that the double click event was altered in qt5 to make it compatable with some other os's

    Is there now a setup option that needs to be configured for Qt5 to enable double clicks or do I need to use a timer to build my own double click detector ?


    SteveH

  2. #2
    Join Date
    Jan 2009
    Location
    Midlands UK
    Posts
    62
    Thanks
    6
    Thanked 9 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt5 - mouseDoubleClickEvent

    Still no joy finding any references to problem - either it's so obvious that no one has wrote about it or it's still a problem.

    Either way I simply used a QTimer and a few lines of code in a mousePressEvent to get around the problem. Also this way it seperates out single and double presses as exclusive events rather than giving single press or single press + doubleclick events.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt5 - mouseDoubleClickEvent

    I don't see any magic in the source code. Qt simply checks the double-click interval time reported by the style and if two subsequent mouse presses are within that interval, it sends a double click event.

    Qt Code:
    1. ulong doubleClickInterval = static_cast<ulong>(qApp->styleHints()->mouseDoubleClickInterval());
    2. doubleClick = e->timestamp - mousePressTime < doubleClickInterval && button == mousePressButton;
    3.  
    4. // ...
    5.  
    6. if (doubleClick) {
    7. mousePressButton = Qt::NoButton;
    8. const QEvent::Type doubleClickType = frameStrut ? QEvent::NonClientAreaMouseButtonDblClick : QEvent::MouseButtonDblClick;
    9. QMouseEvent dblClickEvent(doubleClickType, localPoint, localPoint, globalPoint,
    10. button, buttons, e->modifiers);
    11. dblClickEvent.setTimestamp(e->timestamp);
    12. QGuiApplication::sendSpontaneousEvent(window, &dblClickEvent);
    13. }
    To copy to clipboard, switch view to plain text mode 

    Maybe you are getting NonClientAreaMouseButtonDblClick and not MouseButtonDblClick?

    Quote Originally Posted by SteveH View Post
    Either way I simply used a QTimer and a few lines of code in a mousePressEvent to get around the problem. Also this way it seperates out single and double presses as exclusive events rather than giving single press or single press + doubleclick events.
    So with a single click you first get mouse release event and then mouse press event?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Qt5 - mouseDoubleClickEvent

    Not trying to hijack the thread but this is apropos to the OP.

    If I create (QtCreator 2.6.2) a simple "MainWindow" project and override QMainWindow::event() with SteveH's code above I get the following when double clicking:

    Compiled with Qt 4.8.0:
    mouseButtonPress
    mouseButtonRelease
    mouseButtonDblClick
    mouseButtonRelease
    The same code compiled against Qt 5.0.1 produces only :
    mouseButtonPress
    mouseButtonRelease
    mouseButtonPress
    mouseButtonRelease
    Yet the following code:
    Qt Code:
    1. #include <QtWidgets>
    2.  
    3. class MainWindow : public QMainWindow
    4. {
    5. bool event(QEvent *event)
    6. {
    7. if((event->type() >= 2) && (event->type() < 5))
    8. qDebug() << (int)event->type() ;
    9. return true;
    10. }
    11. };
    12.  
    13. int main(int argc, char *argv[]){
    14. QApplication app(argc, argv);
    15. MainWindow w;
    16. w.show();
    17. app.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 
    compiled against 5.0.1 produces:
    mouseButtonPress
    mouseButtonRelease
    mouseButtonPress
    mouseButtonDblClick
    mouseButtonRelease
    I tried stepping through the code with the debugger but got pretty lost in the sources.

    Any clue as to what's going on, Wysota?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt5 - mouseDoubleClickEvent

    Yes, he didn't "return true" from his code Thus the first press might have gotten propagated to the parent (if any) and subsequent press event didn't manage to get associated with the first one. Furthermore it is crucial to always call the base class implementation. In your codes this is not important as nothing interesting happens in QWidget::event() that is related to mouse events but in a general case not calling that method could break things.
    Last edited by wysota; 8th March 2013 at 09:45.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Qt5 - mouseDoubleClickEvent

    Okay, I guess i am hijacking the thread.

    I agree with what you said. I changed the code to forward the event to the base class, but still no double click event in a QMainWindow project.

    Furthermore QWidget and QDialog class based projects do detect a double click.

    I am just curious as to why the behavior is different.

  7. #7
    Join Date
    Jan 2009
    Location
    Midlands UK
    Posts
    62
    Thanks
    6
    Thanked 9 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt5 - mouseDoubleClickEvent

    Thanks wysota and norobro for your replies.

    1 - My error not setting return code in my example (cut & paste from a void type event), adding a 'true' return code has not changed the results

    2 - I've tried this on 3 different computers running xp/win7 with Qt4.8 & 5.0.1 & creator 2.6.2 development kit - all give same results

    3 - My old program (which runs my karting business) was ok under Qt4.8 on all pc's - it just won't recognise double clicks on Qt5

    4 - My solution using a QTimer is a bit of a hack - ok it seperates single and double clicks but the single click wont be returned until the timer timesout (which the user can definately notice and is usually after the release event) and I have to save any event variables needed of first press. This hack works for the above program in the way it's being used by the staff and gives me breathing space to delve deeper or wait for a better solution from more experianced heads.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt5 - mouseDoubleClickEvent

    Most likely because you were clicking the central widget and trying to implement clicking in mainwindow itself but it is an academic discussion. Last time you said it worked on QMainWindow so I'm not even sure what we're talking about.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    norobro (8th March 2013)

  10. #9
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Qt5 - mouseDoubleClickEvent

    Quote Originally Posted by wysota View Post
    Most likely because you were clicking the central widget and trying to implement clicking in mainwindow
    Yep, that's it. But the central widget forwarded the event to the mainwindow in 4.8. As SteveH points out, that has been changed in 5.0.

Similar Threads

  1. Replies: 6
    Last Post: 17th June 2010, 08:41
  2. MouseDoubleClickEvent on a QGraphicsScene
    By paolom in forum Qt Programming
    Replies: 6
    Last Post: 6th October 2009, 11:01
  3. mouseDoubleClickEvent on QGraphicsItem's
    By been_1990 in forum Qt Programming
    Replies: 11
    Last Post: 7th August 2009, 02:52
  4. mouseDoubleClickEvent in QGraphicsItemGroup
    By dima in forum Qt Programming
    Replies: 0
    Last Post: 9th March 2009, 07:01
  5. Problem of mouseDoubleClickEvent
    By Sarma in forum Qt Programming
    Replies: 18
    Last Post: 8th March 2006, 06:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.