Placing widgets in a toolbar created in QtDesigner.
-
So I had to figure out that it is not possible to place any widget in a toolbar using the designer. I wonder if it is just the Designers gui or if it is a limitation of the ui XML format. So then I place the toolbar manually using
@QAction * QToolBar::insertWidget ( QAction * before, QWidget * widget )@
I wonder about the return type, what exactly does this method return? IMHO void would be appropriate
-
No, it returns a QAction* that is associated with that widget. All items on a toolbar (or a menu, for that matter) are represented by QAction objects. That includes items that are widgets. You should check, but I think that the action returned is actually a [[doc:QWidgetAction]].
You can use this action to put it in a [[doc:QActionGroup]] for instance.
-
Thx for the Quick Replay!
bq. You should check, but I think that the action returned is actually a QWidgetAction.
Yes it is :)
@QAction *action = toolbar->addWidget(myFontComboBox);
QWidgetAction *widgetAction = dynamic_cast<QWidgetAction *>(action);
assert(widgetAction);
assert(dynamic_cast<QFontComboBox *>(widgetAction->defaultWidget())
== myFontComboBox
);@Does this mean I could place an action (or a QWidgetAction) into the toolbar in the designer and then just programmatically set the the desired widget?
-
I have tried, but I could not find an easy way to do that. The problem is that you can't seem to use the promotion feature for QActions. So, I fear that you will just have to add your widget completely from code.