Results 1 to 4 of 4

Thread: QMouseEvent called without pressing buttons

  1. #1
    Join Date
    Jan 2014
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X

    Default QMouseEvent called without pressing buttons

    Dear sirs,
    I have a problem with the mousePressEvent function.
    The program is meant to draw lines using QGLWidget. The program works well when I move the mouse to draw the lines (mouseMoveEvent is called correctly) and when I click the left button (mousePressEvent is called and event->button()=Qt::LeftButton is correctly recognized).
    The problem is that, once clicking the mouse Right Button, mousePressEvent is called and event->button()=Qt::RightButton is correctly recognized, but then the function mousePressEvent is called again and again when I move the mouse. It seems that the event is not consumed after the first mousePressEvent calling.
    I am using Qt5 with MacOs Mountain Lion and the problem was not there when I was using Qt4 (and Snow Leopard as MacOs system).
    The problem occurs in a very long a complicated program, so I am not including the code. But if someone feels it is necessary to take a look in the code I will add it.
    Thank you for any help
    Enrico

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QMouseEvent called without pressing buttons

    Maybe you could try to create a minimal test case, i.e. a program as small as possible that shows the problem.

    This makes it easier to test on other systems and can also be used as a suitable test case when eventually filing a bug report against Qt if it is reprodible by others.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2014
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QMouseEvent called without pressing buttons

    Many thanks anda_skoa.

    I have reduced the program to the minimum level to show where is the problem and the files are attached.
    In the glwidget.cpp file the mousePressEvent, mouseMoveEvent and mouseReleaseEvent have been overloaded as follows:
    void GLWidget::mousePressEvent(QMouseEvent *event)
    {
    if (event->button() == Qt::LeftButton) QMessageBox::critical(0,0,"left","");
    if (event->button() == Qt::RightButton) QMessageBox::critical(0,0,"right","");
    }

    void GLWidget::mouseMoveEvent(QMouseEvent *event) { }

    void GLWidget::mouseReleaseEvent(QMouseEvent *event) { }

    Thus nothing should happen when the mouse is moved without clicking the buttons, while a message box with the text "left" or "right" should open when one of the buttons is clicked.
    Everything works fine till I click the right button. Then the message box is correctly displayed, but then it continues to be displayed when the mouse is moved without any further button clicking. Why????
    It doesn't happen with the left button.
    I guess that the problem is not with the code and that it depends on some malfunctioning of my mouse (actually, a trackpad) or on a bug with Qt5.
    Do anyone can give me some advice?
    Many thanks in advance
    Enrico
    Attached Files Attached Files

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QMouseEvent called without pressing buttons

    Have you tried with qDebug() output instead of the message boxes?

    Message box for debugging seems rather intrusive, moving focus and potentially mouse event target.

    Cheers,
    _

Similar Threads

  1. Replies: 9
    Last Post: 8th July 2013, 08:41
  2. Replies: 2
    Last Post: 12th May 2010, 14:27
  3. QWizard: avoid to go next when pressing enter [Qt4.5]
    By kalos80 in forum Qt Programming
    Replies: 2
    Last Post: 3rd June 2009, 17:11
  4. Dialog closes on pressing Esc key?
    By vishal.chauhan in forum Qt Programming
    Replies: 6
    Last Post: 3rd July 2008, 08:53
  5. closing of window on pressing ESC key
    By raghvendramisra in forum Newbie
    Replies: 2
    Last Post: 7th January 2008, 02:36

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.