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. Can't change margins of items inside QMenuBar
Forum Update on Tuesday, May 27th 2025

Can't change margins of items inside QMenuBar

Scheduled Pinned Locked Moved Solved General and Desktop
qmenubarqmenu
3 Posts 2 Posters 1.5k 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.
  • R Offline
    R Offline
    RBLL
    wrote on last edited by
    #1

    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!

    jsulmJ 1 Reply Last reply
    0
    • R RBLL

      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!

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • R Offline
        R Offline
        RBLL
        wrote on last edited by
        #3
        QMenuBar
        {
            spacing: 0px;
        }
        

        That did it! Thank you very much!

        1 Reply Last reply
        0

        • Login

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