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. [SOLVED] setAttribute and setBackgroundRole. Trying to set a dark background
Qt 6.11 is out! See what's new in the release blog

[SOLVED] setAttribute and setBackgroundRole. Trying to set a dark background

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 14.0k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hello!

    I've tried to set the background colour with

    @setBackGroundRole(QPalette::Dark);@

    But didn't work. Then I tried with

    @setAttribute(Qt::WA_NoBackGround);@

    And worked (at least it showed a dark screen...). I've read "this":http://qt-project.org/forums/viewthread/3239, and the "docs":http://qt-project.org/doc/qt-4.8/qwidget.html#setBackgroundRole, but I don't know why the first approach doesn't work. By the way, the doc say:

    bq. You can modify the palette or set a style sheet if you don't achieve the result you want with setBackgroundRole()

    If it wouldn't work, why? Somebody knows? Is there any difference between showing no background and setting a dark one?

    Thanks

    1 Reply Last reply
    1
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by A Former User
      #2

      Hi QMartin,

      The setBackgroundRole method let you use a color role for the background, which means one of the predefined color of the style applied to the widget. So your are basically limited to the style and its colors.

      So if you don't achieve the result you want (i.e. if the style applied don't have the color/brush you want), use palette or style sheets.

      Here is the style sheet way
      @
      myWidget->setStyleSheet("* { background-color: rgb(50, 50, 50); }");
      @

      This will change your widget background color to a dark gray.

      1 Reply Last reply
      1
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Wow, I think this was the fastest solved thread :D

        Thanks a lot! Best regards!

        1 Reply Last reply
        1
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          You're welcome ! :)

          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