Simone Mariottini
Simone Mariottini

Reputation: 125

Set priority between vertical and horizontal QToolBar positioning

I've searched for quite a long time, but I haven't managed to find a solution to this problem: In QtCreator, I have a main window with 2 QToolBars, one vertical (Qt::LeftToolBarArea) and one horizontal (Qt::BottomToolBarArea). The idea is to have a main toolbar on the left and a secondary toolbar on the bottom, with just a few widgets.

Now the problem is that no matter what I try, when adding the bottom toolbar, the left one shrinks in height to make space for it. Is it possible to invert the behaviour? Have the bottom toolbar shrinked to make space for the vertical one?

Qt documentation doesn't seem to deny this possibility: QMainWindow generic layout with no specification about horizontal toolbars being more "important" than others

Looking around I found this guy with the same problem (no luck, though): https://forum.qt.io/topic/62936/qtoolbar-positioning-within-qmainwindow

And this other picture, but I'm not sure it's official: Possible priority (undocumented) between toolbars

Does somebody knows if this is a lost cause or there's some trick to achieve what I'm looking for?

EDIT:

I've found exactly the thing I'm looking for, unfortunately it seems to be available only for QDockWidgets: http://doc.qt.io/archives/qt-4.8/qmainwindow.html#setCorner

Upvotes: 3

Views: 744

Answers (1)

A.Fagrell
A.Fagrell

Reputation: 1100

Since Qt4, toolbars occupy their own areas around the central widget with fixed positions, so I don't believe there's a simple solution do to what you want by using the QToolBar directly. However, there is a simple solution with QDockWidgets (as you've pointed out). Simply put each QToolBar inside a separate QDockWidget and use QMainWindow::setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea)

I currently don't have access to a compiler but should be something like:

QMainWindow mainWindow;
mainWindow.setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);

auto dock = new QDockWidget("Dock", &mainWindow);
auto windowInsideDock = new QMainWindow(dock, Qt::Widget);
auto toolBar = new QToolBar(windowInsideDock);
windowInsideDock->addToolBar(toolBar);
dock->setWidget(insideDock);
mainWindow.addDockWidget(Qt::LeftDockWidgetArea, dock);
//... similar for bottom widget...

Upvotes: 0

Related Questions