Results 1 to 5 of 5

Thread: QToolButton margins

  1. #1
    Join Date
    Jan 2007
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QToolButton margins

    Hello everyone,

    I'm trying to display the QToolButtons in my QToolBar in a specific way. To achieve the look I want I need to set the spacing between toolbuttons to 0. However, I don't know how to do that, I always get a 1px space between each QToolButton.

    Anyone know a solution?

    Cheers!

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QToolButton margins

    I guess you could try with:
    Qt Code:
    1. toolbar->layout()->setSpacing(0);
    To copy to clipboard, switch view to plain text mode 
    but I'm not sure if it works.

  3. #3
    Join Date
    Jan 2007
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QToolButton margins

    Quote Originally Posted by marcel View Post
    I guess you could try with:
    Qt Code:
    1. toolbar->layout()->setSpacing(0);
    To copy to clipboard, switch view to plain text mode 
    but I'm not sure if it works.
    Unfortunately, it doesn't work. I see no changes.

    Any other ideas?

  4. #4
    Join Date
    Jan 2007
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QToolButton margins

    ok, I found the solution myself, though it's not perfect. As you cannot change the layout for the toolbar itself, you add a QWidget with a layout of your choice (spacing = 0 in my case) to the toolbar and add your toolbar items to that widget... it breaks the functionality to dock the toolbar horizontally and vertically though.

  5. #5
    Join Date
    Dec 2024
    Posts
    1
    Qt products
    Qt3
    Platforms
    MacOS X Symbian S60

    Default Re: QToolButton margins

    You can customize the spacing of the QToolButtons by applying a stylesheet to your QToolBar. Use the following line of code to set the margin to zero: slope game

    toolbar.setStyleSheet("QToolButton { margin: 0px; padding: 0px; }")

    This will remove any default spacing and ensure the buttons are displayed without any gaps.

Similar Threads

  1. QToolButton and Style sheet
    By desch in forum Qt Programming
    Replies: 8
    Last Post: 1st December 2007, 09:38
  2. QToolButton text alignment
    By Vladimir in forum Qt Programming
    Replies: 6
    Last Post: 2nd March 2007, 08:42
  3. Problem with qtoolbutton
    By moowy in forum Qt Programming
    Replies: 1
    Last Post: 22nd September 2006, 14:30
  4. Need help with QToolButton
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 22nd April 2006, 15:55
  5. margins in QSimpleRichText
    By Pan Wojtas in forum Qt Programming
    Replies: 3
    Last Post: 10th February 2006, 17:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.