temp
temp

Reputation: 129

How to set stylesheet for multiple buttons but not all

I'm using a .qss file to set stylesheet for QPushButton I want to give some buttons a different style than other buttons... Is there any way to do this? Maybe something like

QPushButton#thisbutton{
...
}

Upvotes: 1

Views: 1722

Answers (2)

Andy Brown
Andy Brown

Reputation: 5522

In QT Designer, add a custom property and call it class:

enter image description here

Set the value for this:

enter image description here

In a CSS style sheet set formatting for this class:

enter image description here

That's it!

Upvotes: 3

for a normal QButton you can do it like you write above:

QPushButton{ color: blue}

if you can, then extend with inheritance the button and do:

MyNewButtonClass{color: red}

or you can directly with the name of the object directly:

QPushButton#okButton { color: gray }

update:

you can ofcourse set the style of buttons without duplicating the sheet...you just do:

QPushButton#okButton, QPushButton#acceptButton, QPushButton#cancelButton
{
    color: green 
}

Upvotes: 1

Related Questions