Search code examples
c++qtqt-creatorqt5qt-designer

Add QWidgetAction to QMenu through qtcreator/qtdesigner


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

I can add a widget through the code like that:

//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 same behavior using ui designer - it only lets me add QAction and QMenu classes as parts of QMenuBar/QMenu, and does not give option to promote QAction to QWidgetAction. Is there a way to add QWidgetAction and a widget associated with it through designer to have them as part of Ui namespace and their properties editable through ui editor?


Solution

  • Unfortunately that's not possible.