Important: Please read the 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:


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

        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 ?

  • QMenuBar
        spacing: 0px;

    That did it! Thank you very much!

Log in to reply