Results 1 to 4 of 4

Thread: QMenuBar's height has suddenly changed - bug?

  1. #1

    Default QMenuBar's height has suddenly changed - bug?

    I had a QWidget displaying a complex layout containing many widgets.

    The code was approximately:

    Qt Code:
    1. #ifndef Q_OS_MAC
    2. QMenuBar *newMenu = createMenus();
    3. outerLayout->addWidget(newMenu);
    4. #endif
    5.  
    6. QHBoxLayout * h_layout = new QHBoxLayout;
    7. h_layout->setContentsMargins(0,0,0,0);
    8. h_layout->setSpacing(0);
    9. h_layout->addWidget(newDocumentsDocklet);
    10. h_layout->addWidget(newEditorsDocklet);
    11.  
    12. outerLayout->addLayout(h_layout);
    13. window->setLayout(outerLayout);
    To copy to clipboard, switch view to plain text mode 

    This is the result:

    01MCm.png

    Unfortunately, when I changed my h_layout from QHBoxLayout to QSplitter, the QMenuBar changed its height. I don't understand if this is a bug, as I thought the the QMenuBar had a specific height.

    The new code looks like this:

    Qt Code:
    1. #ifndef Q_OS_MAC
    2. QMenuBar *newMenu = createMenus();
    3. outerLayout->addWidget(newMenu);
    4. #endif
    5.  
    6. QSplitter * h_layout = new QSplitter;
    7. h_layout->setOrientation(Qt::Horizontal);
    8. h_layout->addWidget(newDocumentsDocklet);
    9. h_layout->addWidget(newEditorsDocklet);
    10.  
    11. outerLayout->addWidget(h_layout);
    12. window->setLayout(outerLayout);
    To copy to clipboard, switch view to plain text mode 

    This is the new rendering:

    KCU9e.png

    Is somebody able to help me understand why this has happened? And a way to solve this?

  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: QMenuBar's height has suddenly changed - bug?

    You don't show the code, but I assume "outerLayout" is a QVBoxLayout. What you see is probably due to the layout policy of the VBox. When you add a QWidget and another layout to the VBox, it will expand the layout to fill the space not occupied by the QWidget's preferred size. When you add two QWidget instances to a VBox, it will give them equal height unless you call setStretch() to change the layout ratio.

    I'm not really sure why you are manually adding a QMenu and QWidgets to a layout, though. QMainWindow will give a you a menu, and you can set the QMainWindow's centralWidget() to your QSplitter. This will give you exactly the behavior you see in your first case and also behave properly on resize, etc.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3

    Default Re: QMenuBar's height has suddenly changed - bug?

    Thank you d_stranz.
    You are actually right: "outerLayout" is a QVBoxLayout.
    I already have a QMainWindow, but some users would prefer to be able to duplicate the mainWindow into many (ideally infinite) new windows.

    For this reason I add a new menu to every additional new window (It would not be a problem for Macintosh, but this is the only way I have found to have it work in Linux).

    I have followed your suggestion, and I have rewritten the code as follows, adding the QSplitter to a Layout to have it stretched automatically, but the result is still the same:

    Qt Code:
    1. QSplitter * central_body = new QSplitter;
    2. central_body->setOrientation(Qt::Horizontal);
    3. central_body->addWidget(newDocumentsDocklet);
    4. central_body->addWidget(newEditorsDocklet);
    5.  
    6. QVBoxLayout * central_body_layout = new QVBoxLayout;
    7. central_body_layout->addWidget(central_body);
    8.  
    9. outerLayout->addLayout(central_body_layout);
    10. window->setLayout(outerLayout);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    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: QMenuBar's height has suddenly changed - bug?

    What you wrote was not what I suggested. I actually didn't suggest anything - I pointed out why there was a difference in behavior between your different implementations. Adding an extra VBox layout inside your existing VBox layout doesn't do anything useful, as you can see.

    For a real suggestion, I suggest you remove the extra VBox, and instead change the sizePolicy() of the menu bar to have a vertical size policy of "Fixed".
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Project suddenly doesn't compile
    By vieraci in forum Qt Programming
    Replies: 16
    Last Post: 7th June 2016, 07:12
  2. QT Android application suddenly crashes
    By Reiji in forum Qt Programming
    Replies: 1
    Last Post: 3rd June 2015, 13:25
  3. Suddenly Nothing Happens
    By Atomic_Sheep in forum Qt Programming
    Replies: 2
    Last Post: 17th September 2013, 11:54
  4. suddenly datareadProgress total = 0
    By SpeedxDevil in forum Newbie
    Replies: 1
    Last Post: 12th July 2012, 09:21
  5. Suddenly getting 'undefined ref to 'WinMain@16'
    By Doug Broadwell in forum Qt Programming
    Replies: 8
    Last Post: 4th December 2008, 18:11

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.