Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Get default style sheets for different OS
Forum Updated to NodeBB v4.3 + New Features

Get default style sheets for different OS

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 2.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • apalomerA Offline
    apalomerA Offline
    apalomer
    wrote on last edited by apalomer
    #1

    I am developing a cross-platform application, and it looks way worse in Windows that in Ubuntu. This has to do only with the default style sheet for Windows vs the one for Ubuntu. Is there a way to obtain the OS-dependent style sheet that is applied to an application? I have tried to retrieve the application style sheet with:

    QApplication app(argc, argv);
    qDebug() << "Style sheet: " << app.styleSheet();
    

    But this produces an empty string (unless you have manually set it to something). My intention is to retrieve the Ubuntu style sheet and save it to a file (and add it to the resources list), so I can then load it for the application in both OS:

    QApplication app(argc, argv);
    QFile file(":/ubuntu_style.qss");
    file.open(QFile::ReadOnly);
    QString styleSheet = QLatin1String(file.readAll());
    app.setStyleSheet(styleSheet);
    

    Any ideas on how to get the default style sheet of the OS?

    P.S. This question is also asked in stack overflow

    JonBJ J.HilkJ 2 Replies Last reply
    0
    • apalomerA apalomer

      I am developing a cross-platform application, and it looks way worse in Windows that in Ubuntu. This has to do only with the default style sheet for Windows vs the one for Ubuntu. Is there a way to obtain the OS-dependent style sheet that is applied to an application? I have tried to retrieve the application style sheet with:

      QApplication app(argc, argv);
      qDebug() << "Style sheet: " << app.styleSheet();
      

      But this produces an empty string (unless you have manually set it to something). My intention is to retrieve the Ubuntu style sheet and save it to a file (and add it to the resources list), so I can then load it for the application in both OS:

      QApplication app(argc, argv);
      QFile file(":/ubuntu_style.qss");
      file.open(QFile::ReadOnly);
      QString styleSheet = QLatin1String(file.readAll());
      app.setStyleSheet(styleSheet);
      

      Any ideas on how to get the default style sheet of the OS?

      P.S. This question is also asked in stack overflow

      J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote on last edited by
      #3

      @apalomer if you want the same style across platforms you'll have to design your own or use fusion

      QApplication a(argc, argv);
      a.setStyle(QStyleFactory::create("Fusion"));
      

      IIRC Fusion is the default one for linux


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      JonBJ 1 Reply Last reply
      2
      • apalomerA apalomer

        I am developing a cross-platform application, and it looks way worse in Windows that in Ubuntu. This has to do only with the default style sheet for Windows vs the one for Ubuntu. Is there a way to obtain the OS-dependent style sheet that is applied to an application? I have tried to retrieve the application style sheet with:

        QApplication app(argc, argv);
        qDebug() << "Style sheet: " << app.styleSheet();
        

        But this produces an empty string (unless you have manually set it to something). My intention is to retrieve the Ubuntu style sheet and save it to a file (and add it to the resources list), so I can then load it for the application in both OS:

        QApplication app(argc, argv);
        QFile file(":/ubuntu_style.qss");
        file.open(QFile::ReadOnly);
        QString styleSheet = QLatin1String(file.readAll());
        app.setStyleSheet(styleSheet);
        

        Any ideas on how to get the default style sheet of the OS?

        P.S. This question is also asked in stack overflow

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #2

        @apalomer
        There is no in-built stylesheet. You do have to set it yourself. hence why it is empty initially. I do not think Qt supplies anything OS -specific (unless I am mistaken?). So just supply two files, and at runtime/compile-time (there are Qt #define/#ifdefs for the OS you are compiling for) read in/stipulate the one for the OS?

        1 Reply Last reply
        2
        • apalomerA apalomer

          I am developing a cross-platform application, and it looks way worse in Windows that in Ubuntu. This has to do only with the default style sheet for Windows vs the one for Ubuntu. Is there a way to obtain the OS-dependent style sheet that is applied to an application? I have tried to retrieve the application style sheet with:

          QApplication app(argc, argv);
          qDebug() << "Style sheet: " << app.styleSheet();
          

          But this produces an empty string (unless you have manually set it to something). My intention is to retrieve the Ubuntu style sheet and save it to a file (and add it to the resources list), so I can then load it for the application in both OS:

          QApplication app(argc, argv);
          QFile file(":/ubuntu_style.qss");
          file.open(QFile::ReadOnly);
          QString styleSheet = QLatin1String(file.readAll());
          app.setStyleSheet(styleSheet);
          

          Any ideas on how to get the default style sheet of the OS?

          P.S. This question is also asked in stack overflow

          J.HilkJ Online
          J.HilkJ Online
          J.Hilk
          Moderators
          wrote on last edited by
          #3

          @apalomer if you want the same style across platforms you'll have to design your own or use fusion

          QApplication a(argc, argv);
          a.setStyle(QStyleFactory::create("Fusion"));
          

          IIRC Fusion is the default one for linux


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          JonBJ 1 Reply Last reply
          2
          • J.HilkJ J.Hilk

            @apalomer if you want the same style across platforms you'll have to design your own or use fusion

            QApplication a(argc, argv);
            a.setStyle(QStyleFactory::create("Fusion"));
            

            IIRC Fusion is the default one for linux

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #4

            @J-Hilk
            You will probably tell me to "just go look and see", but so far I've never set any style (theme?) like this on any Qt app. So I guess I have been using "vanilla". Am I missing out? If I plan to release for Lin/Win/Mac, would end users be more pleased with such a style or with none?

            1 Reply Last reply
            0
            • apalomerA Offline
              apalomerA Offline
              apalomer
              wrote on last edited by
              #5

              Is there any way to convert the QStyle* that is returned from QStyleFactory::create to a style sheet so I have access to the whole list of widgets and properties? I know I can apply my stylesheet modifying only certaint elements after the QStyleFactory::create style is loaded.

              JonBJ 1 Reply Last reply
              0
              • apalomerA apalomer

                Is there any way to convert the QStyle* that is returned from QStyleFactory::create to a style sheet so I have access to the whole list of widgets and properties? I know I can apply my stylesheet modifying only certaint elements after the QStyleFactory::create style is loaded.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #6

                @apalomer
                No. Read through https://stackoverflow.com/questions/28841705/how-to-obtain-entire-qt-stylesheet-for-qmacstyle where someone would like to do this. Read through the comments below the accepted solution.

                1 Reply Last reply
                1

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved