2 Attachment(s)
QMenuBar's height has suddenly changed - bug?
I had a QWidget displaying a complex layout containing many widgets.
The code was approximately:
Code:
#ifndef Q_OS_MAC
outerLayout->addWidget(newMenu);
#endif
h_layout->setContentsMargins(0,0,0,0);
h_layout->setSpacing(0);
h_layout->addWidget(newDocumentsDocklet);
h_layout->addWidget(newEditorsDocklet);
outerLayout->addLayout(h_layout);
window->setLayout(outerLayout);
This is the result:
Attachment 12302
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:
Code:
#ifndef Q_OS_MAC
outerLayout->addWidget(newMenu);
#endif
h_layout->setOrientation(Qt::Horizontal);
h_layout->addWidget(newDocumentsDocklet);
h_layout->addWidget(newEditorsDocklet);
outerLayout->addWidget(h_layout);
window->setLayout(outerLayout);
This is the new rendering:
Attachment 12303
Is somebody able to help me understand why this has happened? And a way to solve this?
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.
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:
Code:
central_body->setOrientation(Qt::Horizontal);
central_body->addWidget(newDocumentsDocklet);
central_body->addWidget(newEditorsDocklet);
central_body_layout->addWidget(central_body);
outerLayout->addLayout(central_body_layout);
window->setLayout(outerLayout);
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".