0

Actual Behaviour

I ordered my toolbars in the top area in two lines, something like

MyMainWindow::init()
{
    addToolBar(Qt::TopToolBarArea, m_toolbar_1);
    addToolBar(Qt::TopToolBarArea, m_toolbar_2);

    addToolBarBreak(Qt::TopToolBarArea);

    addToolBar(Qt::TopToolBarArea, m_toolbar_3);
    addToolBar(Qt::TopToolBarArea, m_toolbar_4);
    addToolBar(Qt::TopToolBarArea, m_toolbar_5);
}

leading to a results similar to this example using Qt Designer. As you can see the top tool bars are layed out in two lines. Toolbars are layed out over two lines

Now it is very common that the toolbars in the second line (that is m_toolbar_3, m_toolbar_4 and m_toolbar_5) get hidden. This causes the whole second line to disappear, as can be seen in the following screenshot. enter image description here

Desired Behaviour

I want the second toolbar line to be always shown, no matter if there are visible toolbars in it or not.

This is to avoid visual noise of constantly appearing/disappearing tool bars. The visual noise is especially recognisable in the central widget (where "Form ..." is placed), which is either moved up or down.

Is there a way to do that?

mfuchs
  • 2,190
  • 12
  • 20
  • It seems that the only way to do that is to either patch Qt, or to have a dummy invisible toolbar. – Kuba hasn't forgotten Monica Sep 13 '15 at 17:25
  • Should the user be able to change the order of the QToolBars or change their position inside the gui, or should the QToolBars always stay on the same spot? – Gombat Sep 14 '15 at 08:26
  • @Gombat does not really matter for me. So if the solution would only allow fixed ones I'd got for that or vice versa. – mfuchs Sep 14 '15 at 20:31

2 Answers2

0

This may not be the best solution ever, but it should work.

QToolBar has a visibilityChanged signal.

You could connect that to a slot, for example :

connect(m_toolbar, SIGNAL(visibilityChanged(bool)), this, SLOT(onVisibilityChanged(bool)))

Where :

onVisibilityChanged(bool visible)
{
    if(false == visible)
    {
        m_toolbar.setVisible(true);
    }
}
Simpsons
  • 476
  • 1
  • 7
  • 17
  • It is ok if toolbars become invisible. Actually I change their visibility programmatically, depending on what tool bars are supported by the currently selected command. So keeping them all visible is unfortunately not an option for me. It is the eventually empty tool bar line that should stay visible. – mfuchs Sep 14 '15 at 20:34
0

If it is ok that toolbars stay on the same spot no matter what you could simply set them to non-movable. QToolBar::setMovable to false.

Gombat
  • 1,994
  • 16
  • 21
  • The problem is that I change the visibility of the toolbars. So depending on the selected command it might be that there is no tool bar visible on the second line. If there is no tool bar visible Qt hides the second line, leading to visual distraction and disorientation. – mfuchs Sep 14 '15 at 20:48