Results 1 to 3 of 3

Thread: QToolbar expanding sizePolicy not working properly

  1. #1

    Default QToolbar expanding sizePolicy not working properly

    I have created a main window with two toolbars on the same row. Each toolbar has three buttons on it. However, I would like to have the first toolbar take up all the available space while let the 2nd one stay at minimum. I am trying to do this via sizing policy. I basically took the SDI example from QtDemo and modified the code in void MainWindow::createToolBars() as shown below:

    void MainWindow::createToolBars()
    {
    fileToolBar = addToolBar(tr("File"));
    fileToolBar->addAction(newAct);
    fileToolBar->addAction(openAct);
    fileToolBar->addAction(saveAct);
    fileToolBar->setSizePolicy(QSizePolicy::Expanding,QSizePolicy: :Minimum);

    editToolBar = addToolBar(tr("Edit"));
    editToolBar->addAction(cutAct);
    editToolBar->addAction(copyAct);
    editToolBar->addAction(pasteAct);
    fileToolBar->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::M inimum);
    }

    However, it has no effect at all. QT always let the last toolbar on the same row takes up all the available space.

    Any idea what I did wrong? Thanks for any tips.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QToolbar expanding sizePolicy not working properly

    QMainWindow probably overrides the size policy and resizes the toolbars itself. What happens if you set a maximum size for the last toolbar? Does that get ignored too?

  3. #3

    Default Re: QToolbar expanding sizePolicy not working properly

    It doesn't get ignored. The last toolbar stays at the specified maximum size but the remaining space stays unused after the last toolbar.
    The only workaround I've found so far is implement the sizeHint() of the first toolbar and give it a very large width. But that beats the purpose of the sizingPolicy to the toolbars. In QT3, we used to have setHorizontalStretchable() method. Now that method is gone and the sizing Policy doesn't work. I think this is a bug of QT4.



    Quote Originally Posted by d_stranz View Post
    QMainWindow probably overrides the size policy and resizes the toolbars itself. What happens if you set a maximum size for the last toolbar? Does that get ignored too?

Similar Threads

  1. memcpy not working properly
    By sattu in forum Qt Programming
    Replies: 3
    Last Post: 27th October 2010, 00:33
  2. QTabWidget Expanding sizepolicy
    By Zweistein in forum Qt Programming
    Replies: 0
    Last Post: 25th October 2010, 15:34
  3. ScrollZoomer not working properly..
    By Raghaw in forum Qwt
    Replies: 1
    Last Post: 30th October 2009, 07:51
  4. Replies: 1
    Last Post: 28th February 2007, 09:34
  5. Replies: 1
    Last Post: 2nd June 2006, 00:54

Tags for this Thread

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.