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. Delay time in stylesheet loading

Delay time in stylesheet loading

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 3.5k Views
  • 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.
  • A Offline
    A Offline
    ale82
    wrote on last edited by
    #1

    Hi everyone,

    I made a simple application that should set a stylesheet loading settings from a file.
    I put this->setStylesheet() in the MainWindow 's constructor, right after setupUI().
    It happens that at first mainwindow shows itself plain, and after less than a second, modifications are applied.
    This is an annoying graphic problem.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Set the stylesheet in your main.cpp, using QApplication::setStylesheet().

      (Z(:^

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ale82
        wrote on last edited by
        #3

        if I call a.setStylesheet("background-color:red;") for example, a Qt wanring "Could not parse application stylesheet" is displayed".
        If you mean i have to call some static method QApplication::setStylesheet() the compiler stops.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          No, I do not mean static methods. Try a more explicit QSS, like:
          @
          QMainWindow {
          background-color:red;
          }
          @

          (Z(:^

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ale82
            wrote on last edited by
            #5

            Yes it works, but no evident timing improvement.
            It seems like if stylesheet modifications are processed after showevent...

            In such a case I'd prefer waiting for stylesheet rendering and show the main window after this have happen.
            But I don't know how.

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              Try this:
              @
              // in main.cpp
              QTimer::singleShot(800, mainWindowPointer, SLOT(show()));
              return a.exec();
              @

              It should delay the showing of your mainWindow for 800 ms.

              (Z(:^

              1 Reply Last reply
              0
              • A Offline
                A Offline
                ale82
                wrote on last edited by
                #7

                That's funny, it waits 800ms, shows the plain white window, and change the stylesheet with evident time lapse.
                Even if I change the stylesheet form the UI form the effect is the same, and I forgot to say, but it's obvious, that timing differences depends on the stylesheet type, it increase for gradients for example.

                Mybe the sequence is that the stylesheet engine works after the show event...

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  ale82
                  wrote on last edited by
                  #8

                  I noticed that it has the same behaviour if I iconize the window and then I show it clicking on the icon.
                  It shows the plain window and then fill the stylesheet with time.
                  Maybe could be my PC extremly slow and this effetc emphasizes more than usual.

                  1 Reply Last reply
                  0
                  • sierdzioS Offline
                    sierdzioS Offline
                    sierdzio
                    Moderators
                    wrote on last edited by
                    #9

                    [quote author="ale82" date="1390907896"]Maybe could be my PC extremly slow and this effetc emphasizes more than usual.[/quote]

                    This could be the case. I have seen some really heavy QSS code that took up to 4 seconds to load... but it never exhibited the behaviour you have mentioned. In my case, the whole GUI was loading in the background and once it was shown, it already had the styling applied.

                    (Z(:^

                    1 Reply Last reply
                    0

                    • Login

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