Important: Please read the Qt Code of Conduct -

[SOLVED] qApp - How to use a "clean" StyleSheet

  • Hi,

    I would like to set a global stylesheet so that all windows/dialog get the same appearance in my application.
    Right now i'm using 1 stylesheet for MainWindow, and 1 other for a LoginDialog.
    Since LoginDialog is not a children of MainWindow, the stylesheet doesn't get applied and I have to copy my huge stylesheet from MainWindow over there.

    My _problem _is that I have to maintain the stylesheet at 2 places and it's messy.. I would like to fix that.
    I know you can use qApp.setStylesheet to cover all the application, but editing the stylesheet in the qtCreator editor is a nightmare (bad aligment, no error check..) I would like to use QDesigner editor and keep my stylesheet at one place. Is there a fast solution for this ? I tried passing MainWindow as parent to LoginDialog, but it doesn't work (cannot convert from 'MainWindow' to 'QWidget *)

    thanks in advance, here is my Main :

    @int main(int argc, char *argv[]) {

    /// START APP
    QApplication app(argc, argv);
    MainWindow mainWindow;
    /// Global variables
    User *user = new User;
    QNetworkAccessManager *manager = new QNetworkAccessManager;
    app.setProperty("User", QVariant::fromValue<User*>(user));
    app.setProperty("NetworkManager", QVariant::fromValue<QNetworkAccessManager*>(manager));
    /// Login Dialog
    DialogLogin login(mainWindow);  /// this doesn't compile!  I want to because my stylesheet is in MainWindow
    if (login.exec&#40;&#41; != QDialog::Accepted&#41; {
        return 1; // Error, for example
        qDebug() << "not accepted.";
    return app.exec&#40;&#41;;


  • Fixed :

    @ MainWindow mainWindow;
    DialogLogin login;

Log in to reply