Qt Gui Application background color stylesheet
-
wrote on 19 Aug 2012, 13:52 last edited by
I want to set background color for my form
like this
@
body
{
background-color: #fff;
}@
I am using QWidget selector but i only want to change window background;And how i can ise one stylesheet for all windows?
-
wrote on 21 Aug 2012, 09:53 last edited by
Hi AcidLys,
have you read this link. It is very useful. It explains how to use stylesheet.
http://qt-project.org/doc/qt-4.8/stylesheet-syntax.html
If you like to use a stylesheet file for the whole app, then you have to load it in your main.cpp.
Checkout QApplication::setStylesheet();
-
wrote on 23 Aug 2012, 21:22 last edited by
For more information on StyleSheets you can check
"Qt Style Sheets Reference":http://qt-project.org/doc/qt-4.8/stylesheet-reference.html#list-of-properties
"Qt Style Sheets Examples":http://doc-snapshot.qt-project.org/4.8/stylesheet-examples.html
also in order to set the stylesheet for the whole application you can try the following code:
@QFile styleSheet(":/Stylesheet/yourStylesheet.qss"); //path where the file is stored
if (!styleSheet.open(QIODevice::ReadOnly)
{
qWarning("Unable to open ::/Stylesheet/yourStylesheet.qss");
return;
}
qApp->setStyleSheet(styleSheet.readAll());@ -
wrote on 3 Sept 2012, 05:20 last edited by
This does not help in case of message box or a custom widget which i don't know how to be done. I searched the internet before i ask. In case you know, please reply, otherwise no problem.
-
wrote on 3 Sept 2012, 06:46 last edited by
Hi SherifOmran,
do you try to hitchhike this tread?
In the first mail messageBox was not mentioned and it was send by another author.Here, is what you are looking for, I got it from the qt documentations:
@*[environment="##ENV"] QMessageBox{
background-color: ##INACTIVE;
border: 3px solid ##EXTRA_DARK;
}*[environment="##ENV"] QMessageBox QPushButton{
border-radius: 8px;
icon-size: 28px;
min-height: 42px;
max-height: 42px;
min-width: 50px;
background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 ##NORMAL, stop: 0.1 ##INACTIVE, stop:0.15 ##NORMAL, stop:0.9 ##NORMAL, stop:1 ##EXTRA_DARK);
border: 0px solid none;
border-right: 2px solid ##NORMAL;
border-left: 2px solid ##NORMAL;
}*[environment="##ENV"] QMessageBox QPushButton:pressed,
*[environment="##ENV"] QMessageBox QPushButton:checked{
background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 ##EXTRA_DARK, stop: 0.1 ##PRESSED, stop:0.8 ##PRESSED, stop:0.9 ##NORMAL, stop:1 ##PRESSED);
border: 2px solid ##PRESSED;
}@ -
wrote on 3 Sept 2012, 06:57 last edited by
[quote author="messi" date="1346654781"]Hi SherifOmran,
do you try to hitchhike this tread?
In the first mail messageBox was not mentioned and it was send by another author.[/quote]
The actual discussion for the message box was going "on this thread":http://qt-project.org/forums/viewthread/20041/ so for the implementation I directed him here, not his fault :)
Thanks for the code messi :)
-
wrote on 3 Sept 2012, 07:07 last edited by
Ok.
Anyway, almost every widget/dialog is styleable. Always a good approach is to checkout the qt sourcecode directly.In my code you have to replace the ##...... with your own color. Also the conditional clause in the square brackets are optional.
-
wrote on 3 Sept 2012, 10:05 last edited by
Oh, I am sorry, did nt realize it is another thread.
-
wrote on 3 Sept 2012, 10:20 last edited by
If I am allowed to ask. What does *[environment="##ENV"] mean? and what should I put instead of #ENV?
I don't find it in the documentation. Any link?
-
wrote on 3 Sept 2012, 16:03 last edited by
The code is quite complicated and it would need a long explanation.
Remove all *[environment="##ENV"] and replace all words with ## with color value.For more info please checkout the following links.
http://qt-project.org/doc/qt-4.8/stylesheet-syntax.html
http://qt-project.org/doc/qt-4.8/stylesheet-customizing.html