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



  • 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.



  • 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



  • 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



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



  • 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.



  • 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.



  • [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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.