Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Stylesheets : Unable to use ID Selector

I am learning to use the Qt Stylesheet to add different styles to my application. I looked online and saw the Qt Documentation which said that you can use something called ID Selector that can apply the theme to certain objects. This is how I implemented this feature :

QPushButton#button
{
    color:red;
}

But it doesn't work. It only works when I try without the ID Selector:

QPushButton
{
    color:red;
}

Why doesn't this work ? I used copy and paste, so I'm 100% sure that I didn't got the name wrong.

like image 782
Hung Truong Avatar asked Dec 02 '25 14:12

Hung Truong


1 Answers

I found out the answer, and it's actually really simple. I forgot to add button->setObjectName("Name");, which caused the stylesheet to not know about the button. Just add in this line of code and it should work properly.

like image 100
Hung Truong Avatar answered Dec 05 '25 09:12

Hung Truong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!