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
QtWS25 Last Chance

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 13 Jan 2020, 21:03 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!

    J 1 Reply Last reply 14 Jan 2020, 06:37
    0
    • R RBLL
      13 Jan 2020, 21:03

      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!

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 14 Jan 2020, 06:37 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 14 Jan 2020, 14:03 last edited by
        #3
        QMenuBar
        {
            spacing: 0px;
        }
        

        That did it! Thank you very much!

        1 Reply Last reply
        0

        1/3

        13 Jan 2020, 21:03

        • Login

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