How to add stretchable spacer in Qtoolbar?
16,807
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);
Related videos on Youtube
Author by
steffen
I am a Python freak and data nerd. Also, I am experimenting with creating videos on youtube. About Python and data. ¯(°_o)/¯ https://www.youtube.com/channel/UCG9XNnq9LodijOBpIVy1ILg
Updated on June 15, 2022Comments
-
steffen about 2 years
I want some of my toolbar actions appear left-bound and some right-bound. I Gtk I remember adding a stretchable (expandable) separator. How do I achieve that in Qt?
I use Qt Creator but I am not afraid of editing source, so either solution is greatly appreciated.
-
steffen over 11 yearsI used it right after ui->setupUi with insertWidget() instead of addWidget() in order to place the space where I want it to be.
-
Exa over 8 yearsNote 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);