[Qt-interest] Question about StyleSheets
Carsten Breuer
CarstenBreuerQt at textwork.de
Thu Jul 29 23:02:07 CEST 2010
Hi Rob,
> I’m starting to use stylesheets now in my Qt Apps. I have a Widget
> called WgtLogViewer that I call “setObjectName” in the constructor to
> set the object name to “LogViewer”.
I had the same problem. The annoying thing of stylesheets is that
there is almost no way to get rid of it. Stylesheets are cascading
and it is a good way to be as specific on the component you want to
style as you can. Use as much selectors (::), class names (#),
inheritance (>) and properties [] in your definitions as you can to
reduce the unwanted impact of stylesheets to other components.
In your case it could be enaugh to exchange the position of the two
definitions. Nonetheless there are some other ways to get it done:
1. Stylesheets set with creator or with setStylesheet overrules
the ones in global definitions.
2. It is a big difference, if a stylessheet is set on the mainWindow
or the application.
3. Properties are a good way to switch/activate stylesheets.
4. Be as specific as you can to select a component that you
want to style. A generic approach like styling QWidget
lead to more problems then solving them.
5. There are still some bugs in QT with stylesheets (e. g.
styling boarder of QTabWidget).
My 3 cents:
- Setting the stylesheet in the LogViewer class or in
designer/creator will work.
- QWidget[type="LogViewer] in combination with setProperty also.
- Setting the font without QWidget{} will also work.
Best regards,
Carsten
More information about the Qt-interest-old
mailing list