Using Stylesheets

The Qt style sheets lets us customize the look & feel of our widgets without subclassing them. Keep in mind, though, that the best way to use a style sheet is by creating customized "themes" for the application, so that all ui components will look more or less in the same spirit. Although designing a theme can take some time, once it's done everything looks better.

Be sure to include the qss file in a Qt resource file under the /styles directory for this to work.
Once you have the qss ready, using it on an app is a breeze, here's the code (and a sample qrc file):

void MainWindow::loadStyleSheet(const QString &name)
    QFile f(QString(":/styles/%1.qss").arg(name));

    if ( )
// style sheets should only have latin1 chars
        QString styleSheet = QLatin1String(file.readAll());

    <qresource prefix="/">

Stylesheet Lab

Design the following registration form using a stylesheet.