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. Widget background color at runtime
QtWS25 Last Chance

Widget background color at runtime

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 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.
  • JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #1

    Qt 5.12.2, Linux, default GNOME desktop.

    I have

    QWidget with Grid Layout
        QLabel
        QGroupBox
        QGroupBox
        ...
        
    

    I set the top-level QWidget stylesheet to background-color: ....

    In Qt Designer this looks perfect --- the whole widget, its background, all its descendants are colored.

    However, at run-time it comes out with all the descendants (label, group boxes) themselves colored but not the background of the widget itself, between children (i.e. where the grid layout is). That background area remains "white" (or whatever the default window color is).

    What do I have to do? Is this some Linux/desktop flag/setting which comes into play at run-time to do with the window background color?? [At run-time this QWidget is being made a QMdiSubWindow, via QMdiArea::addSubWindow(QWidget), if that is relevant?]

    J.HilkJ 1 Reply Last reply
    0
    • J.HilkJ J.Hilk

      @JonB

      thats a bug in Qt, you have 3 options:

      • upgrade to 5.12.6/7
      • only set stylesheets in designer
      • only set stylesheets in code

      Edit:
      found the related bug report:
      https://bugreports.qt.io/browse/QTBUG-79545

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

      @J-Hilk
      Dear @J-Hilk,

      At the time I accepted your suggestion that my problem was a Qt 5.12.2 issue, as per the bug report. I worked around it by setting the color on the conveniently-available parent widget.

      However, I now discover that my problem is as per my post at https://forum.qt.io/topic/115640/how-to-see-the-area-detected-by-qmouseevent/9, i.e. I need to add:

      myDerivedWidget->setAttribute(Qt::WA_StyledBackground, true);
      

      and then the background color works at run-time.

      Your bug report may well apply, but I don't think it's my case here. I trust you will understand if I now mark this post as the solution to my issue here!

      1 Reply Last reply
      2
      • JonBJ JonB

        Qt 5.12.2, Linux, default GNOME desktop.

        I have

        QWidget with Grid Layout
            QLabel
            QGroupBox
            QGroupBox
            ...
            
        

        I set the top-level QWidget stylesheet to background-color: ....

        In Qt Designer this looks perfect --- the whole widget, its background, all its descendants are colored.

        However, at run-time it comes out with all the descendants (label, group boxes) themselves colored but not the background of the widget itself, between children (i.e. where the grid layout is). That background area remains "white" (or whatever the default window color is).

        What do I have to do? Is this some Linux/desktop flag/setting which comes into play at run-time to do with the window background color?? [At run-time this QWidget is being made a QMdiSubWindow, via QMdiArea::addSubWindow(QWidget), if that is relevant?]

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by J.Hilk
        #2

        @JonB

        thats a bug in Qt, you have 3 options:

        • upgrade to 5.12.6/7
        • only set stylesheets in designer
        • only set stylesheets in code

        Edit:
        found the related bug report:
        https://bugreports.qt.io/browse/QTBUG-79545


        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 2 Replies Last reply
        4
        • J.HilkJ J.Hilk

          @JonB

          thats a bug in Qt, you have 3 options:

          • upgrade to 5.12.6/7
          • only set stylesheets in designer
          • only set stylesheets in code

          Edit:
          found the related bug report:
          https://bugreports.qt.io/browse/QTBUG-79545

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

          @J-Hilk
          Thank you. I was mixing design- & run-time stylesheets here, and was about to mark yours as solution, but it seems to happen to me with design-time only too.

          On a hunch, after QMdiArea::addSubWindow(QWidget) I retrieve QWidget::parentWidget() (which I think is something like a viewport to do with MDI window) and I set its stylesheet to have the background color there. Lo & behold, the whole widget is now colored! So at least in my case I am marking this as solution, whether or not your bug applies, though thank you very much.

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

            @JonB

            thats a bug in Qt, you have 3 options:

            • upgrade to 5.12.6/7
            • only set stylesheets in designer
            • only set stylesheets in code

            Edit:
            found the related bug report:
            https://bugreports.qt.io/browse/QTBUG-79545

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

            @J-Hilk
            Dear @J-Hilk,

            At the time I accepted your suggestion that my problem was a Qt 5.12.2 issue, as per the bug report. I worked around it by setting the color on the conveniently-available parent widget.

            However, I now discover that my problem is as per my post at https://forum.qt.io/topic/115640/how-to-see-the-area-detected-by-qmouseevent/9, i.e. I need to add:

            myDerivedWidget->setAttribute(Qt::WA_StyledBackground, true);
            

            and then the background color works at run-time.

            Your bug report may well apply, but I don't think it's my case here. I trust you will understand if I now mark this post as the solution to my issue here!

            1 Reply Last reply
            2

            • Login

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