QAction isChecked is a function in the Qt framework that is used to retrieve whether an action is currently checked or not. This function is commonly used in menus, toolbars, and other user interface elements to indicate whether an action is currently active or not.
Syntax: bool isChecked() const;
Example 1: QAction isChecked Usage
In this example, we create a new action and check if it is currently checked or not. If the action is checked, we print a message to the console.
#include #include #include #include
int main(int argc, char *argv[]) { QApplication app(argc, argv);
QMenuBar menuBar;
QAction *action = new QAction("Test", &menuBar); action->setCheckable(true); action->setChecked(true);
menuBar.addAction(action);
if (action->isChecked()) { qDebug() << "Action is Checked"; }
menuBar.show();
return app.exec(); }
Output: Action is Checked
Example 2: QAction isChecked Usage
In this example, we create two actions and toggle their checked states by clicking on them. We then check their checked state after each click.
#include #include #include #include
int main(int argc, char *argv[]) { QApplication app(argc, argv);
QMenuBar menuBar;
QAction *action1 = new QAction("Test 1", &menuBar); action1->setCheckable(true); action1->setChecked(false);
QAction *action2 = new QAction("Test 2", &menuBar); action2->setCheckable(true); action2->setChecked(false);
Package Library: QAction isChecked is a part of the Qt framework, specifically the QtWidgets library.
C++ (Cpp) QAction::isChecked - 30 examples found. These are the top rated real world C++ (Cpp) examples of QAction::isChecked extracted from open source projects. You can rate examples to help us improve the quality of examples.