Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Can't change margins of items inside QMenuBar



  • Hi,

    I have unwanted spacing in between items of my QMenuBar as shown below:

    7a8015e4-e1d5-4cc0-a4cc-bb744d9b9e42-image.png

    This looks like incorrect margins in between the QMenuBar::item. Therefore, I tried (in my stylesheet) setting the margins to 0 as so:

    QMenuBar::item
    {
        margin-left: 0px;
        margin-right: 0px;
    }
    

    But it doesn't work. I also tried to set it in the code like so:

    test->setContentsMargins(0, 0, 0, 0);
    test1->setContentsMargins(0, 0, 0, 0);
    test10->setContentsMargins(0, 0, 0, 0);
    test100->setContentsMargins(0, 0, 0, 0);
    

    where test* is a QMenu pointe. Again, no changes in the GUI.

    Finally, I also tried in the stylesheet to set QMenu and QMenu::item to no margins. Again, it doesn't work.

    At this point, I'm out of ideas. Any thoughts?

    Thank you!


  • Lifetime Qt Champion

    @RBLL What about "spacing" or "padding" (not sure), see https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qmenubar ?



  • QMenuBar
    {
        spacing: 0px;
    }
    

    That did it! Thank you very much!


Log in to reply