PDA

View Full Version : QPushButton mouse release event issue



Rajesh.Rathod
31st August 2016, 10:52
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,

d_stranz
1st September 2016, 00:56
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:



QMouseEvent event( QEvent::MouseButtonRelease, pos, 0, 0, 0 );
QApplication::sendEvent( button, &event );

Rajesh.Rathod
1st September 2016, 07:56
@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,

d_stranz
1st September 2016, 18:37
we made some design changes to differentiate behavior based on assigned role

Sounds like a better way to go.