1
votes

I've a question about QPushbutton states transition.

I derived a class, say it MyQPushButton, from QPushButton. For it I set some visual properties through stylesheet:

Qt Code: Switch view

MyQPushButton
{
background-color: transparent;
border-image: url(<InstallationPath>/Resources/Images/Buttons/MyQPushButton_a.png);
}

MyQPushButton:pressed {
background-color: transparent;
border-image: url(<InstallationPath>/Resources/Images/Buttons/MyQPushButton_b.png);
}

MyQPushButton:disabled {
background-color: transparent;
border-image: url(<InstallationPath>/Resources/Images/Buttons/MyQPushButton_d.png);
}

MyQPushButton:checked {
background-color: transparent;
border-image: url(<InstallationPath>/Resources/Images/Buttons/MyQPushButton_c.png);
}

To copy to clipboard, switch view to plain text mode

Interacting with a checkable MyQPushButton instance, image "MyQPushButton_b" (pressed state) appears for a while only by clicking on it on unchecked state, during the transition from unchecked to checked. I would expect to see the same image for a while also by clicking on it on checked state (reverse transition) as in the documentation http://doc.qt.io/qt-5/qabstractbutton.html is reported:

"When the user clicks a toggle button to check it, the button is first pressed then released into the checked state. When the user clicks it again (to uncheck it), the button moves first to the pressed state, then to the unchecked state."

Is my interpretation wrong? Conversely, how could I "force" the pressed state corresponding image to be shown during the checked-unchecked transition?

Thank you!!!

IR

1

1 Answers

1
votes

Change pressed to down. The down property covers both pressed and checked states, however, so make sure your stylesheet fully overrides the appearance changes made by down (it does already, but this is just an N.B.).

The "pressed" state the documentation refers to is a non-entity referring to the button being "down" but not "checked". This is equivalent to the following:

if (button.isDown() && !button.isChecked())
    ...

Diving into the code shows this test is used internally with QPushButton::initStyleOption().