In my widget, I can do something like that:
MyWindow::MyWindow(QWidget *parent) :
QWidget(parent)
{
ui.setupUi(this);
setStyleSheet("QWidget { background-color: red }"); // <--- HERE
}
This will set the widget background red.
I have a QSS file in my resources. How do I instruct my widget to take its style sheet content from there, vs just taking the qss syntax as parameter?
As an alternative to setting a style sheet for each widget, you can just load and set a stylesheet for a whole application. Something like this:
QApplication app( argc, argv );
// Load an application style
QFile styleFile( ":/style.qss" );
styleFile.open( QFile::ReadOnly );
// Apply the loaded stylesheet
QString style( styleFile.readAll() );
app.setStyleSheet( style );
In this case all widgets will pick their styles from the given stylesheet automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With