How can i make QPushButton look like hovered by mouse using QStyle? Maybe Style Flags or something else?
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.
J-P Nurmi
I know that i can do it by using QStyle::State :
Qt Code:
QStyleOptionButton sob; sob.initFrom(this); }To copy to clipboard, switch view to plain text mode
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.Qt Code:
To copy to clipboard, switch view to plain text mode
J-P Nurmi
Apocalypse (30th March 2008)
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
Qt Code:
To copy to clipboard, switch view to plain text mode
J-P Nurmi
It did nothing. Maybe i must delete some more flags?
Are you sure? Which style is that? With some styles it's just hard to notice the difference when there's no text:
J-P Nurmi
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.
J-P Nurmi
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?
J-P Nurmi
Sure. It means that ~QStyle::State_Enabled given't result and button still look like enabled. To make button disabled i use :
Qt Code:
QStyleOptionButton sob; sob.initFrom(this);To copy to clipboard, switch view to plain text mode
~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.
Qt 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(); }To copy to clipboard, switch view to plain text mode
J-P Nurmi
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:
Qt Code:
Widget() { button->move(0,50); button->setDisabled(true); button->setText("Disabled PushButton"); button->show(); this->resize(200,200); }To copy to clipboard, switch view to plain text mode
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:
Qt Code:
// sets the palette of this opt.initFrom(this); // "this" is not disabled so we switch the color group by handTo copy to clipboard, switch view to plain text mode
J-P Nurmi
Apocalypse (31st March 2008)
That's it! Thank you!
Bookmarks