Results 1 to 4 of 4

Thread: QPushButton mouse release event issue

  1. #1
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QPushButton mouse release event issue

    Dear All,
    I have a QPushButton for which I have set stylesheet to show different color for press and release state.

    The problem is, when this button is pressed it shows file save dialog and after dialog execution is completed button still shows its pressed state until I refresh it by clicking somewhere else on application.

    Note that because of some specific requirement i have to show file save dialog on button press event, so I am using its pressed signal here.

    I am using function QFileDialog::getSaveFileName for this operation.

    It seems to me that button is not getting mouse release event.

    Any idea , please advise.

    Thanks,
    Last edited by Rajesh.Rathod; 31st August 2016 at 09:57.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QPushButton mouse release event issue

    The QFileDialog::getSaveFileName() static method invoke a modal dialog, so the button loses focus. As a result, it never sees the mouse up event.

    What you are doing is very non-standard behavior for a push button. Whoever is making this "specific requirement" does not seem to know much about accepted practice for user interaction.

    In any case, you can send the button an event after your dialog method returns to force it back to an unpressed state:

    Qt Code:
    1. QMouseEvent event( QEvent::MouseButtonRelease, pos, 0, 0, 0 );
    2. QApplication::sendEvent( button, &event );
    To copy to clipboard, switch view to plain text mode 
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPushButton mouse release event issue

    @d_stranz
    Thank you very much for your important feedback.

    There are many reason for this kind of functionality behavior in my project but one of main reason is, there is list of functionality which can be assigned to this button in my project and one of them has behavior like press and hold to perform some operation.

    Anyway but after your feedback, we made some design changes to differentiate behavior based on assigned role and it solved my issue.

    Thank you,

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QPushButton mouse release event issue

    we made some design changes to differentiate behavior based on assigned role
    Sounds like a better way to go.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 2
    Last Post: 26th February 2015, 08:53
  2. Getting mouse release event system-wide
    By rittchat in forum Newbie
    Replies: 4
    Last Post: 9th February 2012, 08:08
  3. Replies: 14
    Last Post: 17th January 2012, 09:01
  4. Replies: 3
    Last Post: 7th January 2012, 08:38
  5. QPushButton mouse pointer event
    By ahmdsd_ostora in forum Qt Programming
    Replies: 2
    Last Post: 16th August 2010, 13:44

Tags for this Thread

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.