I want some of my toolbar actions to appear left-bound and some right-bound. In GTK, I remember adding a stretchable (expandable) separator. How do I achieve that in Qt?
How to add a stretchable spacer in a QToolbar?
Duplicate of #2062478 –
Saltish
Does this answer your question? How do I align a QWidget to the right of a QToolBar? –
Lucchesi
You can use an empty widget with automatic expanding, it works like the spacers you can use in Qt Designer:
tb = my_toolbar;
QWidget* empty = new QWidget();
empty->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
tb->addWidget(empty);
tb->addWidget(otherWidget);
I used it right after ui->setupUi with insertWidget() instead of addWidget() in order to place the space where I want it to be. –
Biggs
Note that this only works for toolbars which are attached on the top or bottom of your window. For toolbars that are attachable to the left or right you also need to set the vertical size policy to Expanding:
empty->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
–
Farly © 2022 - 2024 — McMap. All rights reserved.