How can i make QPushButton look like hovered by mouse using QStyle? Maybe Style Flags or something else?
Printable View
How can i make QPushButton look like hovered by mouse using QStyle? Maybe Style Flags or something else?
I recommend taking a look at sources when you want to find these things out (QPushButton::initStyleOption() or something similar in your case). It's a state flag passed in QStyleOption.
I know that i can do it by using QStyle::State :
But this given't result, button still look like State_Enabled. Maybe i did something wrong?
They are flags. You should combine a set of flags by using OR operator:
Notice what QStyleOption::initFrom() docs say.. It already initializes state so basically you overrode it with plain QStyle::State_MouseOver.
One more question. What flag can make that button look like Disabled?
So remove QStyle::State_Enabled which has been turned on by QStyleOption::initFrom(). It's all about simple bitwise operations :)
It did nothing. Maybe i must delete some more flags?
No, i'm using Oxygen style and ~QStyle::State_Enabled doesn't works for me. Maybe i must do something else?
Try with other style to verify it works? Well, at least it works perfectly for me. :)
It doesn't works with other styles. Do you know another variants?
Could you show the current code of yous and explain what does "does not work" mean in your case? :)
Sure. It means that ~QStyle::State_Enabled given't result and button still look like enabled. To make button disabled i use :
~QStyle::State_Sunken works and button become enabled. But i want to make it disabled. I tried to delete initFrom, but it didn't worked too;
Could you do me a favor: compile the following code and run it with "-style motif" arguments.
Code:
// main.cpp #include <QtGui> { public: { QStyleOptionButton opt; opt.state = 0; opt.text = "Disabled"; opt.text = "Enabled"; opt.text = "Disabled,Sunken"; opt.text = "Enabled,Sunken"; } }; int main(int argc, char* argv[]) { Widget w; w.show(); return a.exec(); }
Yes, you are right. The button looks like disabled in motif and other squared styles.
But i need another effect. To explain what i want i made next addition into your code:
Code:
Widget() { button->move(0,50); button->setDisabled(true); button->setText("Disabled PushButton"); button->show(); this->resize(200,200); }
And i made 4 screensots off app in few styles. You can find it in attachment. Could you tell me how can i draw my button same as "Disabled PushButton"?
Try setting the palette to use "disabled" colors:
Code:
// sets the palette of this opt.initFrom(this); // "this" is not disabled so we switch the color group by hand
That's it! Thank you!