PDA

View Full Version : Layout QActions in a QToolBar



parisiasl
11th March 2010, 18:06
Hi,
I've a QToolBar with 30 Actions : one column of 30 Icons.
I want organize this Actions in 2 Colums of 15 items for column.
I think to create a Vertical Layout, and insert in this Layout 15 Horizontal Layouts.
Then in every Horizontal Layouts add two QActions.

But the layout with the QActions in the QToolBar don't works :
I Post a little example, with only one icon (QAction) :

1. I Create a Widget (w1) with only a QAction.
2. I Create an HorizontalLayout (hl) and i set to it the Widget (w1)
3. I Create a new Widget (w2)
4. I Set to w2 the layout (hl) that contains the other widget (w1).
5. I Add the w2 widget to the toolBar.




QWidget *w1 = new QWidget();
w1->addAction(myAction); // myAction is QAction*;

QHBoxLayout *hl = new QHBoxLayout();
hl->addWidget(w1);

QWidget *w2 = new QWidget();
w2->setLayout(hl);
toolBar->addWidget(w2);



This code don't works. In the Toolbar nothing appears.
How can I manage the layout in the ToolBar ?
Thank you
Salvo

wysota
11th March 2010, 20:42
QWidget::addAction() doesn't do what you want. You need to manually create a QToolButton for each action, then assign the action to the button and place the button in the layout.

parisiasl
12th March 2010, 14:40
Thank you!
Works very well!