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. how to make a QToolbar's "margin" miminum?
Forum Update on Monday, May 27th 2025

how to make a QToolbar's "margin" miminum?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 5.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.
  • O Offline
    O Offline
    opengpu2
    wrote on last edited by
    #1

    how to make a QToolbar's "margin" miminum?
    because there is only text button on my toolbar, so there is a lot of blank space in the four direction on the toolbar around the buttons.
    is there any way to make these blank space smaller?
    i tried setSizePolicy, setContentMargin, but seems not work.
    thank you

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You can do that with stylesheets, e.g.

      QToolBar { padding: 0; }
      QToolBar QToolButton { padding: 0; margin: 0; }
      
      O 2 Replies Last reply
      0
      • Chris KawaC Chris Kawa

        You can do that with stylesheets, e.g.

        QToolBar { padding: 0; }
        QToolBar QToolButton { padding: 0; margin: 0; }
        
        O Offline
        O Offline
        opengpu2
        wrote on last edited by
        #3

        @Chris-Kawa thank you

        1 Reply Last reply
        0
        • Chris KawaC Chris Kawa

          You can do that with stylesheets, e.g.

          QToolBar { padding: 0; }
          QToolBar QToolButton { padding: 0; margin: 0; }
          
          O Offline
          O Offline
          opengpu2
          wrote on last edited by
          #4

          @Chris-Kawa but i use a QWidget to contain 2 QToolBar, on each QToolBar, i include some QAction....
          i want the whole QWidget padding, margin equal to 0....how?
          thank you

          1 Reply Last reply
          0
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by Chris Kawa
            #5

            I'm not sure what you mean but if the toolbars are in a layout then you can do this:

            yourWidget->layout()->setContentsMargins(0,0,0,0);
            yourWidget->layout()->setSpacing(0);
            

            If you mean something else please provide a code sample or an image of what you have and what you want.

            O 1 Reply Last reply
            0
            • Chris KawaC Chris Kawa

              I'm not sure what you mean but if the toolbars are in a layout then you can do this:

              yourWidget->layout()->setContentsMargins(0,0,0,0);
              yourWidget->layout()->setSpacing(0);
              

              If you mean something else please provide a code sample or an image of what you have and what you want.

              O Offline
              O Offline
              opengpu2
              wrote on last edited by
              #6

              @Chris-Kawa thank you

              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