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] Change background color of QToolBar doesn't work in Linux
Forum Update on Monday, May 27th 2025

[SOLVED] Change background color of QToolBar doesn't work in Linux

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 12.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.
  • B Offline
    B Offline
    Bambo
    wrote on 30 Jan 2013, 13:28 last edited by
    #1

    Hi,
    i have this simply code in Linux (xubuntu):
    @MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
    {
    mainToolBar = new QToolBar;
    mainToolBar->setAutoFillBackground(true);
    mainToolBar->setStyleSheet("QToolBar { background: yellow; }");

    addToolBar(Qt::TopToolBarArea, mainToolBar);
    

    }@

    if toolbar is in Top, the background color is default
    if toolbar is in Left, the background color is yellow
    why?
    how can i change color of Top QToolBar?

    images for ilustration:
    !http://www.stud.fit.vutbr.cz/~xadami06/bug1.png(bug)!
    !http://www.stud.fit.vutbr.cz/~xadami06/bug2.png(bug)!

    (in windows it works correct)

    Thanks for reply.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      messi
      wrote on 30 Jan 2013, 14:56 last edited by
      #2

      Hi Bambo

      please, always tell us which version of Qt did you use and which linux distribution.

      I did a quick test and it worked under Qt 4.7.0 with ubuntu 10.10

      BTW mainToolBar->setAutoFillBackground(true); is not necessary if you work with stylesheet.
      It is only neccessary when you are working with QPalette.

      Cheers

      messi

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Bambo
        wrote on 30 Jan 2013, 15:02 last edited by
        #3

        Hi Messi,
        I use:

        • Qt 5.0.0
        • Xubuntu 12.10

        I try it also under Qt 4.8.x, Ubuntu 12.10 and it doesn't work too.

        Bambo

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Adrien Leravat
          wrote on 30 Jan 2013, 15:29 last edited by
          #4

          Could you try this ? I'm not sure background provides the exact same behavior as background-color.
          @
          QToolBar {
          background-color: yellow;
          }
          @

          Adeneo Embedded - www.adeneo-embedded.com

          1 Reply Last reply
          0
          • M Offline
            M Offline
            messi
            wrote on 30 Jan 2013, 15:46 last edited by
            #5

            Ok I can verify that the example is not working under Lubuntu 12.4 qith Qt4.8.1, 4.8.3 and 5.0.0.
            What I can see is when I move the toolbar around and redock it then i can see the yellow color for a split second.
            When I don't add it to the MainWindow it works.

            It seems to me that the stylesheet of the toolbar will be overwritten by the MainWindow.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Adrien Leravat
              wrote on 30 Jan 2013, 15:53 last edited by
              #6

              Normally, your QSS rule would be overwritten only if you have more specific rules (#name, ::pseudo-state) in parents widgets. A possible explaination would be that the original style isn't fully overwritten.

              You could then try to add the following rule to force a deeper re-styling:
              @
              border: 1px solid black;
              @

              Also check background-color.

              Adeneo Embedded - www.adeneo-embedded.com

              1 Reply Last reply
              0
              • B Offline
                B Offline
                Bambo
                wrote on 31 Jan 2013, 07:52 last edited by
                #7

                [quote author="Adrien Leravat" date="1359561217"]
                You could then try to add the following rule to force a deeper re-styling:
                @
                border: 1px solid black;
                @
                [/quote]
                Thanks! With this it is working.

                1 Reply Last reply
                0

                2/7

                30 Jan 2013, 14:56

                topic:navigator.unread, 5
                • Login

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