QMenu *menu = new QMenu("Menu"); QWidgetAction *widgetAction = new QWidgetAction(menu); QLabel *label = new QLabel("Hello QLabel"); widgetAction ->setDefaultWidget(label); menu->addAction(widgetAction);
QToolBar *toolbar = new QToolBar("ToolBar"); QWidgetAction *widgetAction = new QWidgetAction(this); QSpinBox *spinBox = new QSpinBox(this); widgetAction ->setDefaultWidget(spinBox); toolbar->addAction(widgetAction);This example adds a QSpinBox to a toolbar using QWidgetAction. Package Library: Qt Widgets Module