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. After using my Qt desktop application for a while and also using other applications simultaneously the stylesheet of my Qt desktop application changes.
QtWS25 Last Chance

After using my Qt desktop application for a while and also using other applications simultaneously the stylesheet of my Qt desktop application changes.

Scheduled Pinned Locked Moved Unsolved General and Desktop
stylesheetdesktop
15 Posts 4 Posters 1.1k 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
    andyP
    wrote on last edited by andyP
    #1

    I am using Qt 5.15.3 on Windows 10 and Widgets (no QML).
    At startup my application loads a light theme stylesheet file (style.qss).
    I also set the stylesheet of some QWidgets programatically.
    When I start my program everything looks like I want it.
    But after a while using my application and other programs simultaneously the stylesheets changes.

    As an example I have a QTabWidget with rounded tabs:Tab.PNG

    After a while it looks like this instead:
    TabDrifted.PNG

    As another example I have made a subclass of QPushButton: StartStopButton.
    I am modifying the stylesheet of the button dynamically.
    For instance when starting I want the button to appear green:

    setStyleSheet("StartStopButton{color: #000000; background-color: #00ff00}");
    

    Starting.png

    However when the stylesheet changes the button is instead shown as light blue when starting:
    StartingDrifted.png

    I have installed a global eventFilter on qApp and uses this to get the stylesheet of my button when starting.
    It reports:

    StartStopButton{color: #000000; background-color: #00ff00}
    

    So it seems that my button has the stylesheet I wanted but Qt somehow chooses to ignore this stylesheet!?

    JonBJ 1 Reply Last reply
    0
    • A andyP

      I am using Qt 5.15.3 on Windows 10 and Widgets (no QML).
      At startup my application loads a light theme stylesheet file (style.qss).
      I also set the stylesheet of some QWidgets programatically.
      When I start my program everything looks like I want it.
      But after a while using my application and other programs simultaneously the stylesheets changes.

      As an example I have a QTabWidget with rounded tabs:Tab.PNG

      After a while it looks like this instead:
      TabDrifted.PNG

      As another example I have made a subclass of QPushButton: StartStopButton.
      I am modifying the stylesheet of the button dynamically.
      For instance when starting I want the button to appear green:

      setStyleSheet("StartStopButton{color: #000000; background-color: #00ff00}");
      

      Starting.png

      However when the stylesheet changes the button is instead shown as light blue when starting:
      StartingDrifted.png

      I have installed a global eventFilter on qApp and uses this to get the stylesheet of my button when starting.
      It reports:

      StartStopButton{color: #000000; background-color: #00ff00}
      

      So it seems that my button has the stylesheet I wanted but Qt somehow chooses to ignore this stylesheet!?

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

      @andyP said in After using my Qt desktop application for a while and also using other applications simultaneously the stylesheet of my Qt desktop application changes.:

      But after a while using my application and other programs simultaneously the stylesheets changes.

      I don't think anyone can diagnose this.

      However when the stylesheet changes the button is instead shown as light blue when starting:

      If you replace the first stylesheet rule by the second one you will lose the first stylesheet's green foreground/background, if that is what you mean. Then the light blue presumably comes from some other applicable rule you have.

      H 1 Reply Last reply
      2
      • JonBJ JonB

        @andyP said in After using my Qt desktop application for a while and also using other applications simultaneously the stylesheet of my Qt desktop application changes.:

        But after a while using my application and other programs simultaneously the stylesheets changes.

        I don't think anyone can diagnose this.

        However when the stylesheet changes the button is instead shown as light blue when starting:

        If you replace the first stylesheet rule by the second one you will lose the first stylesheet's green foreground/background, if that is what you mean. Then the light blue presumably comes from some other applicable rule you have.

        H Offline
        H Offline
        Hardy91
        wrote on last edited by
        #3

        @JonB said in After using my Qt desktop application for a while and also using other applications simultaneously the stylesheet of my Qt desktop application changes.:

        But after a while using my application and other programs simultaneously the stylesheets changes.

        same issue I am facing with Qt 5.15.1. Randomly it fall back to the default style and all the stylsheet applied on different widgets get lost. and it is random and only reproduce 3 out 10 try

        JonBJ 1 Reply Last reply
        0
        • H Hardy91

          @JonB said in After using my Qt desktop application for a while and also using other applications simultaneously the stylesheet of my Qt desktop application changes.:

          But after a while using my application and other programs simultaneously the stylesheets changes.

          same issue I am facing with Qt 5.15.1. Randomly it fall back to the default style and all the stylsheet applied on different widgets get lost. and it is random and only reproduce 3 out 10 try

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

          @Hardy91 I don't think anyone can help you with that unless you find some reproducer.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            Hardy91
            wrote on last edited by
            #5

            @JonB I do agree with your point, but the problem is its a big code and I can't share it here. and I try making a small sample application on which it is not reproducing. I even can't post the screenshot of the problem here. but what the OP reported I am facing the exact same issue.
            The real problem here is it is not 100% reproducible and there is no particular step.

            SGaistS 1 Reply Last reply
            0
            • H Hardy91

              @JonB I do agree with your point, but the problem is its a big code and I can't share it here. and I try making a small sample application on which it is not reproducing. I even can't post the screenshot of the problem here. but what the OP reported I am facing the exact same issue.
              The real problem here is it is not 100% reproducible and there is no particular step.

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Hardy91 hi,

              Are you setting your stylesheet only once ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • H Offline
                H Offline
                Hardy91
                wrote on last edited by
                #7

                @SGaist So here is what happing in my class

                1. Inherited the QApplication class and in the constructor of the inherited class setStylesheet() by reading the QSS Stylesheet file.

                getStyleSheetFile( QString fileName )
                {
                QFile file( fileName );
                file.open( QFile::ReadOnly | QFile::Text );
                QString styleSheet = QLatin1String( file.readAll() );
                return styleSheet;
                }

                1. After this, we created so many other widgets and dialog and in some dialogs we set the styesheet where we want different stylesheet.
                2. Now when we run the application most of the time it is working fine and showing the stylesheets as set.
                3. but randomly sometimes it switch back to the qt default style and all the stylesheet is gone on almost all the widget.

                Some key points here.

                1. After stylesheet is gone I opened a dilaog in which I set the stylesheet on QFrame/combobox/radiobutton/pushbutton. (which usually worked as setstylesheet ) is also not applying the stylesheet and showing the default Qt style and some places black or grey backgound. On some push button I even set the border to 0 px is also now showing the border as default style.
                2. I tried to reproduce this issue for about 8 hr and only able to reproduce 2 times. that too randomly.

                Most Important one: our application support the batch execution of some backend operation which updates the UI and those backend operation is executed in a boost thread and through our custom observer design pattern/callbacks it update the UI elements like log widow some labels stylesheet. and mostly this issue reproduce when we perform this operation but its random. During normal operation of application it is working fine.

                SGaistS 1 Reply Last reply
                0
                • H Hardy91

                  @SGaist So here is what happing in my class

                  1. Inherited the QApplication class and in the constructor of the inherited class setStylesheet() by reading the QSS Stylesheet file.

                  getStyleSheetFile( QString fileName )
                  {
                  QFile file( fileName );
                  file.open( QFile::ReadOnly | QFile::Text );
                  QString styleSheet = QLatin1String( file.readAll() );
                  return styleSheet;
                  }

                  1. After this, we created so many other widgets and dialog and in some dialogs we set the styesheet where we want different stylesheet.
                  2. Now when we run the application most of the time it is working fine and showing the stylesheets as set.
                  3. but randomly sometimes it switch back to the qt default style and all the stylesheet is gone on almost all the widget.

                  Some key points here.

                  1. After stylesheet is gone I opened a dilaog in which I set the stylesheet on QFrame/combobox/radiobutton/pushbutton. (which usually worked as setstylesheet ) is also not applying the stylesheet and showing the default Qt style and some places black or grey backgound. On some push button I even set the border to 0 px is also now showing the border as default style.
                  2. I tried to reproduce this issue for about 8 hr and only able to reproduce 2 times. that too randomly.

                  Most Important one: our application support the batch execution of some backend operation which updates the UI and those backend operation is executed in a boost thread and through our custom observer design pattern/callbacks it update the UI elements like log widow some labels stylesheet. and mostly this issue reproduce when we perform this operation but its random. During normal operation of application it is working fine.

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Hardy91 Just to be sure, you are not updating Qt's GUI elements directly from these boost threads ?

                  Does your "custom observer design pattern/callbacks" take that element into account ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  H 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    @Hardy91 Just to be sure, you are not updating Qt's GUI elements directly from these boost threads ?

                    Does your "custom observer design pattern/callbacks" take that element into account ?

                    H Offline
                    H Offline
                    Hardy91
                    wrote on last edited by Hardy91
                    #9

                    @SGaist .
                    my question is, even if this is happening then why this problem is not always, why this is random behavior. I know here we are talking about the threading which no one can predict. but still technically it should reproduce more often not 2 times in 8 hr.

                    Does your "custom observer design pattern/callbacks" take that element into account ?
                    To be honest, I am not sure that it is not happening. But I think it's not otherwise this would be easily reproducible. we are just calling callbacks and there we are emitting the signals to the UI classes and updating the result on UI.

                    Hypothetically even if due to this stylesheet is gone but it should recover when we open a new instance of the QDialog where we set the stylesheet agian.

                    Have you ever seen the same behavior?

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      Hardy91
                      wrote on last edited by
                      #10

                      A similar question posted here

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        There's the catch: calling functions on GUI elements from a different thread is currently in the "undefined behaviour" territory so you might just be lucky that it's not crashing your application at all.

                        What I would start with is to ensure that there's no direct call anywhere. Next step is to check what is connected and how the signals are emitted.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        2
                        • H Offline
                          H Offline
                          Hardy91
                          wrote on last edited by Hardy91
                          #12

                          Hi @SGaist, thanks for your valuable feedback.
                          I resolved this issue.
                          Root-cause: Directly updating the UI components from the non-UI thread(aka main thread). As, the code size is really big it was really challenge to find out where it was happening.

                          Does your "custom observer design pattern/callbacks" take that element into account ?
                          Yes, the framework support this thing, but somewhere it was broken.

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by SGaist
                            #13

                            Glad you found out and fixed it !

                            Since you have it working now, please mark the thread as solved using so other forum users may know a solution has been found :-)

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            0
                            • H Offline
                              H Offline
                              Hardy91
                              wrote on last edited by
                              #14

                              HI @SGaist I am not the OP for this form/question.

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                Right ! Your part was way longer than the original conversation 😅

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                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