Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
custom toolbar layout
i need to have a layout like this:
action, action (a lot space) action
so i thought to create a toolbar, and add actions to it.
i also created a layout where i added
widgetForActions for all the 3 actions:
layout->addWidget(toolbar->widgetForAction(action)); layout->addStretch(); layout->addWidget(toolbar->widgetForAction(action));
but well i can't set the layout on the toolbar since it already has one.
is there a solution to this?
You can try using a QSpacerItem.
i added it like this:
but it only occupies as much space as other actions (i.e. actions which became tool buttons on tool bar)
That looks a bit odd syntax. )
Anyway i checked the docs. not sure it takes one. sorry. my bad.
Anyway, you can do like this
... insert left actions first .. QWidget* empty = new QWidget(); empty->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); ui->mainToolBar->addWidget(empty); // this will be right aligned QAction *test= new QAction(this); test->setText("RIGHT"); ui->mainToolBar->addAction(test);
learned something new today. thanks.
me too. i thought Spacers could be put in any layout :)