drhex
2nd June 2007, 20:45
My main window has a QToolBar with icons for various tools.
If I just addAction()s to the toolbar they show up left adjusted with an equal amount of space between each, which is usually fine.
However, at some places in the toolbar, I need extra space between the icons, and the last icon is supposed to be right-adjusted in the toolbar. In ordinary widgets, those problems could be easily solved by calling addSpacing() and addStrech() on the layout.
I had a (somewhat ugly but) working solution in Qt4.2.3 - for spacing I added a 1x1 pixel transparent icon and for the stretch necessary to right-adjust the last icon I casted the Toolbar's layout() to QBoxLayout, which allowed me to call addStretch().
That last trick won't work anymore in Qt-4.3, QToolBar's layout is a "QToolBarLayout" (not in the docs) and its addItem() (called by addStretch() dies saying I should have called addAction() instead. That hint won't help me since QToolBar::addAction() does not have any spacing or stretch arguments.
Is there a proper way to add stretch to a QToolBar?
If I just addAction()s to the toolbar they show up left adjusted with an equal amount of space between each, which is usually fine.
However, at some places in the toolbar, I need extra space between the icons, and the last icon is supposed to be right-adjusted in the toolbar. In ordinary widgets, those problems could be easily solved by calling addSpacing() and addStrech() on the layout.
I had a (somewhat ugly but) working solution in Qt4.2.3 - for spacing I added a 1x1 pixel transparent icon and for the stretch necessary to right-adjust the last icon I casted the Toolbar's layout() to QBoxLayout, which allowed me to call addStretch().
That last trick won't work anymore in Qt-4.3, QToolBar's layout is a "QToolBarLayout" (not in the docs) and its addItem() (called by addStretch() dies saying I should have called addAction() instead. That hint won't help me since QToolBar::addAction() does not have any spacing or stretch arguments.
Is there a proper way to add stretch to a QToolBar?