Get QSS option programmatically

353 views Asked by At

I have the following problem: I have a custom stylesheet containing a font option * {font-family: "Times New Roman";}. I apply this stylesheet to my application when it is created. After that I need to query this option in my C++ code, but I can't find a right way to do it. I try to call QApplication::font().family() and QWidget().font().family(), but both of these methods returns default values. As far as I can judge QApplication's style is applied to QWidget after it is fully created (maybe when it is shown for the first time, but I'm not sure). Can anybody help?
UPD
The following code illustrates my problem:
.qss:

* {
    font: bold large "Times New Roman";
    font-size: 12px;
}

This style sheet is used to setup QApplication. I want also to have a font from .qss to be used as default font for my QWebView:

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QFile file("default.qss");
    file.open(QIODevice::ReadOnly | QIODevice::Text);
    app->setStyleSheet(file.readAll());
    // some work is done here
    // ...
    QWebView view;
    QFont font = QWidget().font();
    view->settings()->setFontFamily(QWebSettings::StandardFont, font.family());
    view->settings()->setFontSize(QWebSettings::DefaultFontSize, font.pointSize());
    view.show();
    return app.exec();
}
0

There are 0 answers