Qt Stylsheet ID Selector does not work
-
Hi,
i played a bit around with the Stylesheet. I write everything to a txt file and set it here in my MainWindow
My QActions are added in this function. I linked to the important one.
As you can see i set the property name to test123 and specified it in my stylesheet. But it is not black. It has no colour.
i also tried to make the hover border colour different, but it does not work, either.Is there someone how knows why the id selector does not work??
-
Helllo @QT-static-prgm
According to Qt documentation Stylesheet, id selector should be replaced with an object name of a widget :
http://doc.qt.io/qt-4.8/stylesheet-syntax.html#selector-types
ID Selector QPushButton#okButton Matches all QPushButton instances whose object name is okButton.
I think that your mistake is that you are trying to try to use Id selector with QAction ( and QAction is not a widget, QAction does not even have a setStylesheet() function)
-
@mostefa oops. Thank you. I got it working now. But how can i add a image for an QToolButton??
QToolButton#test123:checked { image: url(:/images/toolbar/about.png); } QToolButton#test123 { border-image: url(:/images/toolbar/about.png); border-style: solid; border-width: 1px; border-radius: 5px; border-color: #a4daff; min-height: 25px }
For the checked state image works fine. But for not checked only background and border image work. But that's not what i want.
-
What if you write this for the unchecked state ?
QToolButton#test123:unchecked { border-image: url(:/images/toolbar/about.png); border-style: solid; border-width: 1px; border-radius: 5px; border-color: #a4daff; min-height: 25px }
-
Also on the unchecked state you choosed to put image only on border with border-image property, maybe you want to put your image like checked state? in this case you have just to add :
image: url(:/images/toolbar/about.png);
on unchecked state stylesheet
-
@mostefa that's what did not work. But i found the problem. image works only if there is a border-style.
setting border-style: none works fine