import qgis.PyQt.QtWidgets as QtWidgets # create a QAction instance my_action = QtWidgets.QAction("My Action", parent=None) # set the action as checkable my_action.setCheckable(True)
import qgis.PyQt.QtWidgets as QtWidgets # create a QAction instance my_action = QtWidgets.QAction("My Action", parent=None) # set the action as checkable my_action.setCheckable(True) def on_action_checked(checked): if checked: print("Action is checked") else: print("Action is unchecked") # connect the action with a function my_action.triggered.connect(on_action_checked)In this example, we create a `QAction` instance called `my_action`, and set it as checkable. We also define a function called `on_action_checked` that will be called when the action is checked or unchecked. We use the `connect` function to connect the action with the `on_action_checked` function. Package library: PyQt5.