Using an existing QAction object in a menu with Qt Creator



  • Hello,

    I would like to use an existing QAction that I have instantiated and manipulating it (e.g.: settings some of its properties) in some part of my application and then insert it in a menu bar created through the wysiwyg tools of Qt Creator.

    Let's say the QAction is named myAction
    @
    //Create
    QAction *myAction = new QAction(tr(&Act and Play));

    //Configure
    myAction->setObjectName("ActAndPlay");
    myAction->setCheckable(true);
    ...
    @

    I've tried to add it to a menu created with the wysiwyg menu editor of Qt Creator,
    @
    ui->menuFromQtCreator->addAction(myAction);
    @
    but it the action is appended at the end of the menu, no way to specify its position in the menu.

    Do you know if there is a way to handle this? May be through the metaproperties?

    Thanks


  • Moderators

    If you know the QAction that you want to insert your action before, then you can use "insertAction(),":/doc/qt-4.8/qwidget.html#insertAction which QMenu inherits.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.