Results 1 to 6 of 6

Thread: How do I add a QSpacerItem to a toolbar?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2009
    Posts
    60
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How do I add a QSpacerItem to a toolbar?

    Since a QSpacerItem does not inherit QWidget, I can't use addWidget(). So how do I add a spacer to a toolbar?

  2. #2
    Join Date
    Nov 2007
    Posts
    31
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How do I add a QSpacerItem to a toolbar?

    Quote Originally Posted by di_zou View Post
    Since a QSpacerItem does not inherit QWidget, I can't use addWidget(). So how do I add a spacer to a toolbar?
    You can use QToolBar's addSeparator() or insertSeparator().
    kichi

  3. #3
    Join Date
    Sep 2009
    Posts
    60
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How do I add a QSpacerItem to a toolbar?

    All addSeperator() did was add this little vertical line. I was hoping to add more space and have the ability to customize the scaling and such.

  4. #4
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How do I add a QSpacerItem to a toolbar?

    Quote Originally Posted by di_zou View Post
    All addSeperator() did was add this little vertical line. I was hoping to add more space and have the ability to customize the scaling and such.
    Hi Di_Zou,
    even i'm also trying same thing, to add spaceritem in toolbar. If u've done this, plz tell me how to do.
    Thank u.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  5. #5
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: How do I add a QSpacerItem to a toolbar?

    Add an empty QLabel. The only downside of this I found so far is that you wont be able to move the window around on macos when clicking on that empty space made by the label.
    It's nice to be important but it's more important to be nice.

  6. #6
    Join Date
    Jun 2021
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How do I add a QSpacerItem to a toolbar?

    Add a QWidget instead of a QSpacerItem, set the size policy on the spacer and add the widget to the toolbar.

    Qt Code:
    1. QWidget* spacer = new QWidget();
    2. spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    3. // toolBar is a pointer to an existing toolbar
    4. toolBar->addWidget(spacer);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Grid-like Toolbar
    By dv_ in forum Qt Programming
    Replies: 1
    Last Post: 17th February 2009, 11:37
  2. Toolbar
    By assismvla in forum Qt Programming
    Replies: 1
    Last Post: 17th July 2008, 18:42
  3. how i can add image in my toolbar
    By jyoti in forum Qt Tools
    Replies: 7
    Last Post: 19th December 2006, 15:39
  4. QSpaceritem problem with crashing
    By moowy in forum Qt Programming
    Replies: 2
    Last Post: 3rd November 2006, 20:52

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.