[Solved ] Background color of QMenu by StyleSheet doen't work this



  • Hi, I tried to work with Stylesheet and added in the constructor of my QMainWindow a line
    @
    this->setStyleSheet(" * {background-color: blue;color: yellow;} QPushButton {background-color: red;} QMenu::item::selected {background-color: black;}");
    @

    Basically, it works for all items, but not for the Menubar, which I create by
    @
    m_FileNew = new QAction("new database",this);
    ...
    m_FileMenu = new QMenu("File", this);
    menuBar()->addMenu(m_FileMenu);

    m_FileMenu->addAction(m_FileNew);
    m_FileMenu->addAction(m_FileOpen);
    ...
    @

    However, get GUI, all widgets are colored, even the entries in the menu "new database" etc., but not the "File" entry, where the background color is still gray (as default)

    I tried to google around, but didnt find a solutation yet. Does anyone have an idea, what i got wrong or if there is a workaround.

    kind regards,
    curator



  • Try to set stylesheets for QMenuBar...

    QMenu is a global scope for any kind of a menu, e.g. Context Menu.



  • Hi, thank you for your post.

    Unfortunately, the Menu is neither yellow nor black. So I would expect, that it is already covered by "* {background-color: "

    Am I correct?



  • Yea, it is covered by that, but everything (from Window's background to buttons) will have that background color. And also try to define stylesheets for
    @QMenuBar::item {}@



  • It should be covered, but as I mentioned, ir remains at the original color.

    Maybe it is a different problem:

    Ich tried this example:
    http://codeprogress.com/cpp/libraries/qt/QMenuBarSetMenuBackGround.php#.UTyXnFczSYQ

    But, the Menu1 has NO red background an my PC. They mention problems with qtconfig, but I have no odea, what this means

    regards,
    curator



  • Hi, finally, i made it.

    I had to add the line:
    @app.setStyle(QStyleFactory::create("fusion"));@

    Now it works!

    regards,
    curator



  • thanks. it helped me too.

    add [Solved] in the title.


Log in to reply
 

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