Results 1 to 2 of 2

Thread: Toolbars, floating, and sizing

  1. #1
    Join Date
    Nov 2008
    Posts
    38
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Toolbars, floating, and sizing

    Hi. At the moment I have this in a QMainWindow subclass constructor:
    Qt Code:
    1. thing = new QToolBar(name,this);
    2. addToolBar (Qt::LeftToolBarArea, thing)
    3. // populate thing...
    To copy to clipboard, switch view to plain text mode 
    Which works fine.

    If I resize the main window, the centralWidget is smaller than that size becuase
    the toolbar takes up room. Ideally the resize method would set the centralWidget's size and grow the QMainWindow to fit the toolbars. (If I call resize on the centralWidget, the QMainWindow doesn't seem to respond.)

    Another acceptable solution would be to create the QToolBar to be initially floating, but I can't see how. Omitting the addToolBar call simply means that it has no layout and appears squashed int the QMainWindow's space, and there aren't any QToolBar methods I can see that accomplish this.

    Can you see how to solve either of these niggles?

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Toolbars, floating, and sizing

    Quote Originally Posted by spraff View Post
    If I resize the main window, the centralWidget is smaller than that size becuase
    the toolbar takes up room. Ideally the resize method would set the centralWidget's size and grow the QMainWindow to fit the toolbars. (If I call resize on the centralWidget, the QMainWindow doesn't seem to respond.)
    Basically you have two choices.
    1. Let QMainWindow adjust its size according to its contents using resize(sizeHint()) and adjust layouts so that you are satisfied with the size hint
    2. Use resize(sizeHint()+QSize(addWidth, addHeight)) where addWidth and addHeight are the values which you want to add to the size hint (which you have to calculate manually).

    There is also a third, a bit wacky solution - go even further and ask Qt to calculate the offset for you.
    Qt Code:
    1. QSize margins = size()-centralWidget->size(); // this is the size of "stuff" around the central widget
    2. QSize myDestSize = ...; // set to whatever you want the central widget to be
    3. resize(myDestSize+margins);
    To copy to clipboard, switch view to plain text mode 

    Another acceptable solution would be to create the QToolBar to be initially floating, but I can't see how.
    Probably like this:
    Qt Code:
    1. addToolBar(Qt::NoToolBarArea, thing);
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to wysota for this useful post:

    spraff (26th January 2009)

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.