Qt World Summit: Submit your Presentation

QWidgetAction how to use properly?

  • Hello

    I'd like to create few widgets via QAction system so that they all share the given data.

    Say if I create a QLineEdit and then add that QAction to 3 toolbars. I'd like to upon pressing return to update all instances of that action.

    So if I build something like this for my QWidgetAction instance>

    QWidget *icActionLineEdit::createWidget(QWidget *parent) {
        QLineEdit *edit = new QLineEdit(parent);
        connect(edit, &QLineEdit::returnPressed, [=]() {
            mText = edit->text();
            emit triggered(true);
        connect(this, &icActionLineEdit::triggered, [=]() { edit->setText(mText); });
        return edit;

    This should update/sync the lineEdits when text is pressed?

    I'm not quite sure. As I don't know how I can add 2 QActions of the same action in 1+ toolbars.

    if I just do


    It only adds one of them... so I'm a tad lost & I cant really test the above test...

    Any hints how I can use that system? I want to sync line edits/radio buttons/etc/etc (I think QAction provide radio button via QActionGroup tho)


    Also can I add that QWidgetAction in to normal layout by any chance? Seems like a a great way to synchronize widgets together if I want to show the same lineEdit in multiple areas in my app ?