QAction *action = new QAction("Save", this); action->setShortcut(QKeySequence::Save); connect(action, &QAction::triggered, this, &MyClass::saveFile);
QMenu *menu = new QMenu(this); QAction *action = new QAction("Show Grid", this); action->setCheckable(true); action->setChecked(true); // default checked state connect(action, &QAction::toggled, this, &MyClass::toggleGrid); menu->addAction(action);
QAction *action = new QAction(QIcon(":/images/open.png"), "Open", this); connect(action, &QAction::triggered, this, &MyClass::openFile);In this example, a QAction object is created with the "Open" label and an icon loaded from a resource file. A signal-slot connection is established to call the openFile() slot of MyClass when the action is triggered. Package library: Qt