User6996
User6996

Reputation: 3003

Using theme for my Qt widget application

How to use a theme for my in app/widget in qt embedded, I have follow the following instruction at this url. But it doesn't seem to work not sure why maybe i have missed something

Qt dark orange stylesheet

int main(int argc, char *argv[])
{
    QString file_path = QCoreApplication::applicationDirPath() + "/theme.css";

    QApplication a(argc, argv);
    QApplication::setStyle("plastique");

    MainWindow w;
    QFile style_file(file_path);
    if(style_file.open(QIODevice::ReadOnly))
    {
      qDebug() << "Readin file OK!";
      w.setStyleSheet(style_file.readAll());
      style_file.close();
    }
    w.show();

    return a.exec();
}

I also have upload the "theme.css" file to the same path, file do exists.

Upvotes: 0

Views: 978

Answers (2)

thuga
thuga

Reputation: 12931

You're supposed to put the content of a stylesheet in QWidget::setStyleSheet, not a path to a file. So open your file with QFile, read the contents and set that as your stylesheet.

Here is an example:

QFile style_file("path/to/stylesheet/darkorange.stylesheet");
if(style_file.open(QIODevice::ReadOnly))
    this->setStyleSheet(style_file.readAll());

Upvotes: 0

Nithish
Nithish

Reputation: 1640

Try passing the absolute path to the stylesheet file:

QCoreApplication::applicationDirPath() + QString("darkorange.stylesheet");

Upvotes: 1

Related Questions