QWidgets Stylesheets
-
I am fairly new to QT and am working to see if I can figure out how to build a Qt application.
I am having real trouble with stylesheets, attempting to set them programmaticly. I have tried setting them in the Instantiation method, setting them from the class that instantiates the class and from the main application.
setStyleSheet("border-width: 2px; border-color: Red;");
I know they are being read because if I change border to barder I get 4 messages that the style sheet can't be parsed. Is there something else I have to set to get them to work, or is there a correct place that then need to be set at? Telling me what to go read would be sufficient. I have googled this and so far, none of the suggestions seem to work.
-
Hi
If you start creator, make default new Widget Desktop project,
Add a widget to the design area and right click it. There is Change stylesheet which is
an editor. there you can test if syntax is valid. -
What if I don't use the design area, I want to do it all programatically?
-
said in QWidgets Stylesheets:
border-width: 2px; border-color: Red;
Try Giving it a Border Style... Right now your giving it a width and color but no style to apply it to..
http://www.eatoncode.com/resources/shareit/Screencast_17-18_20-11-2016.mp4
http://doc.qt.io/qt-5.7/stylesheet-examples.html
http://www.w3schools.com/css/css_border.asp
http://www.w3schools.com/css/tryit.asp?filename=trycss_border-style
Hope that helps.
-
setStyleSheet()
is a method on a widget and stylesheets are cascading, meaning they work on the widget you set them on and any children it has.
For example:QWidget* foo = new QWidget(); QWidget* bar = new QWidget(foo); //child of foo foo->setStyleSheet("border: 2px solid red"); //applies to both foo and bar bar->setStyleSheet("background-color: blue"); //applies only to bar
You can set a stylesheet from wherever you have access to the
setStyleSheet()
method. From the constructor, any method or from outside the class. There are no restrictions to it.