QMenu menu; QAction* action = new QAction("Checkable Item", this); action->setCheckable(true); menu.addAction(action);
QToolBar toolbar; QAction* action = new QAction(QIcon("icon.png"), "Checkable Item", this); action->setCheckable(true); toolbar.addAction(action);This code creates a QToolBar instance and adds a QAction instance to it. The setCheckable method is called on the QAction instance to make it checkable. An icon is also set for the toolbar button using the QIcon constructor. The package library that contains the QAction class is the Qt library.