Stretchable QToolBar
-
Hi Guys,
I have created two QToolBar in the top of QMainWindow. Example:
@ QToolBar * leftToolBar = new QToolBar (this);
QToolBar * rightToolBar = new QToolBar(this);leftToolBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); rightToolBar->setFixedWidth(150); leftToolBar->setMovable(false); rightToolBar->setMovable(false); addToolBar(leftToolBar); addToolBar(rightToolBar);@
But left tool bar has size according to its contents, and right tool bar stuck to left. Any combination with tool bars policy does not work.
Is there any way to stretch left tool bar ? May be exists some workaround ? Or it's bug in framework ?
Thanks in advance.
-
Insert widget with QSizePolicy::Expanding into left toolbar using QToolBar::addWidget()
@
QWidget *separator = new QWidget(this);
separator->setSizePolicy(QSizePolicy::Expanding,
QSizePolicy::Expanding);
toolBar->addWidget(separator);
@By the way, such convenience method as QToolBar::addStretch() would be nice. I've had this problem myself, some time ago.
-
[quote author="chernetsov0" date="1312554521"]Insert widget with QSizePolicy::Expanding into left toolbar using QToolBar::addWidget().... I've had this problem myself, some time ago.[/quote]
I tried this one and I saw this solution before, but in case with two bars on one line it doesn't work.
Sorry, just forgot... Right bar has 'RightToLeft' layout direction.
-
[quote author="yuriyb" date="1312554823"]
Right bar has 'RightToLeft' layout direction.
[/quote]Why do you use that?
-
If you want some widgets to be in the far right of the toolbar - just join two toolbar into one and insert that separator between actions of the two.
-
[quote author="chernetsov0" date="1312555595"]If you want some widgets to be in the far right of the toolbar - just join two toolbar into one and insert that separator between actions of the two.[/quote]
How I can join two toolbars ?
I need tool bar like Google Chorme bookmarks bar, where exist place for link buttons and one right button with menu (in chrome 'other bookmarks' tool button).
-
I've tried your solution and buttons on right toolbar seems to be on far right, so what is the problem?
-
Button on far right because 'Right to Left' direction forces tool buttons appear in other order, but I want stretch left bar as far as possible. In my case right tool bar will always contain only one button.
Take a look:
-
I tried almost everything and still no result.
Workaround exists, but requires a lot of extra work.@
QToolBar *toolBar = new QToolBar(this);
toolBar->setMovable(false);QWidget *separator = new QWidget(this);
separator->setSizePolicy(QSizePolicy::Expanding,
QSizePolicy::Expanding);toolBar->addAction("Bookmark 1");
toolBar->addAction("Bookmark 2");
toolBar->addWidget(separator);
toolBar->addAction("More Bookmarks");
@Dynamically updating tool bar contents will be trickery of another kind (that's the hard part).
-
Solution with stretcher before button isn't suitable because in case of toolbar overfill, the right button will be invisible. In my application this tool bar filled from item model and handle signals from model to overload.
I've tried dirty hack with overload resizeEvent in main window and set fixed width for toolbar dinamically, but behaviour also isn't suitable because in time of resizng main window in some cases hangs.
So, do you have any other idea ? As I saw on other forums this problem not just for me.
-
Actually, maybe it's not a bug but rather lack of feature. By default last toolbar get all the toolbar area space. And AFAIK there is no way to change that behavior.
If you remove setMovable(false) statements and try to drag that toolbar right, you will see it's possible to do such a thing at the run time.
So how about trying not to resize toolbar in resizeEvent implementation but moving it? -
By the way, right-to-left layout has nothing to do with issue.
It must, ideally, work without it fine. -
I was solve this problem in my app by another way. I removed border in style sheet and handle context menu requests for both tool bar in one point.
But would not be bad to see correct handling of QToolBar::sizePolicy by framework in next release.
Anyway thanks for your help.