[Solved]Need help with CSS
-
Hello Geeks :)
I'm having some troubles understanding how CSS works with Qt. I have a dialog and I want to define 1 global css for this particular dialog. The CSS should define visuals for different widgets located on my dialog. The problem is that I don't know how to do that. Currently I assign CSS to individual widgets, which causes duplication and I want to avoid that. I tried setting the following CSS to the dialog:
@QLineEdit {
padding: 1px;
border-style: solid;
border: 2px solid gray;
border-radius: 8px;
}
@
But it didn't assign that css to all QLineEdit widgets on that dialog. I'm missing something very trivial but don't know what. Your help is much appreciated.
Thanks -
For the whole app, try:
@
qApp->setStyleSheet("QLineEdit { padding: 1px; border-style: solid; border: 2px solid gray; border-radius: 8px; }");
@Just remember to use it early in your code :) Mind you, this is just one of many possible answers to your question.
-
Oh, and by the way, it's called QSS in Qt :) As it is not really CSS, just similar in syntax and principles.
Also, some links you might find useful:
"Qt Style Sheets":http://developer.qt.nokia.com/doc/qt-4.7/stylesheet.html
"Styles and Style Aware Widgets":http://developer.qt.nokia.com/doc/qt-4.7/style-reference.html#id-a3b2102f-dcbc-49d0-a3f4-d0004fb89606
"The Style Sheet Syntax":http://developer.qt.nokia.com/doc/qt-4.7/stylesheet-syntax.html#id-0c0e1863-8e45-441f-a348-d89e3bbf388b
As the last note, you may also try the new kid on the block, QML (Qt QUICK).