Creating checkboxes
Checkboxes are closely related to radio buttons, in that they offer options around a single theme. However, unlike radio buttons, checkboxes can be selected or unselected. You can also select more than one checkbox at a time. In this recipe, we'll create a dialog with checkboxes and some textboxes to programmatically track which checkboxes are selected.
Getting ready
Open the QGIS Python console by selecting the Plugins menu and then clicking on Python Console.
How to do it...
In this recipe, we'll use a class to manage the checkboxes and the textbox widgets, as follows:
- First, we import the GUI and QGIS core libraries:
from PyQt4.QtCore import * from PyQt4.QtGui import *
- Next, we create our custom class for the checkboxes and textboxes:
class CheckBox(QWidget): def __init__(self, parent=None): QWidget.__init__(self, parent)
- Next, we'll need a layout object to manage the placement of the widgets:
...