custom toolbar layout
-
wrote on 24 Apr 2018, 18:34 last edited by
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
widgetForAction
s 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? -
Hi
You can try using a QSpacerItem.
http://doc.qt.io/qt-5/qspaceritem.html -
Hi
You can try using a QSpacerItem.
http://doc.qt.io/qt-5/qspaceritem.htmlwrote on 24 Apr 2018, 18:46 last edited by@mrjj
hi, thanksi added it like this:
toolbar->addWidget(QSpacerItem(4000, 1)->widget());
but it only occupies as much space as other actions (i.e. actions which became tool buttons on tool bar)
-
@mrjj
hi, thanksi added it like this:
toolbar->addWidget(QSpacerItem(4000, 1)->widget());
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);
-
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);
wrote on 24 Apr 2018, 19:12 last edited by@mrjj
learned something new today. thanks. -
@mrjj
learned something new today. thanks.@user4592357
me too. i thought Spacers could be put in any layout :) -
@user4592357
me too. i thought Spacers could be put in any layout :)wrote on 24 Apr 2018, 19:21 last edited by@mrjj :)
1/7