Add QWidgetAction to QMenu via qtcreator / qtdesigner

I am wondering if there is a way to add a QWidgetAction to QMainwindow-> QMenuBar-> QMenu using qtcreator or qtdesigner.

I can add a widget through this code:

//ui->myMenu is QMenu in QMenuBar of QMainWindow
QWidgetAction *act = new QWidgetAction(ui->myMenu);  
QLineEdit* edt = new QLineEdit("I am Line edit",ui->myMenu);
//setup edt ...
act->setDefaultWidget(edt);
ui->myMenu->addAction(act);

It compiles and works as expected.

However, I cannot achieve the same behavior with ui designer - it allows me to add QAction and QMenu classes as part of QMenuBar / QMenu and does not allow the promotion of QAction in QWidgetAction. Is there a way to add a QWidgetAction and the widget associated with it through the constructor, to use them as part of the Ui namespace and their properties editable with the ui editor?

+4
1

, .

+5

Source: https://habr.com/ru/post/1525819/


All Articles