Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    2
    4
    12502
    Loading More Posts
    • 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.
    • Q
      QMartin last edited by

      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 Reply Quote 1
      • A
        Adrien Leravat last edited by Adrien Leravat

        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.

        Adeneo Embedded - www.adeneo-embedded.com

        1 Reply Last reply Reply Quote 1
        • Q
          QMartin last edited by

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

          Thanks a lot! Best regards!

          1 Reply Last reply Reply Quote 1
          • A
            Adrien Leravat last edited by

            You're welcome ! :)

            Adeneo Embedded - www.adeneo-embedded.com

            1 Reply Last reply Reply Quote 1
            • First post
              Last post