Book Image

QGIS Python Programming Cookbook

Book Image

QGIS Python Programming Cookbook

Overview of this book

Table of Contents (16 chapters)
QGIS Python Programming Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. First, we import the GUI and QGIS core libraries:

    from PyQt4.QtCore import *
    from PyQt4.QtGui import *
    
  2. Next, we create our custom class for the checkboxes and textboxes:

    class CheckBox(QWidget):
      def __init__(self, parent=None):
          QWidget.__init__(self, parent)
    
  3. Next, we'll need a layout object to manage the placement of the widgets:

    self.layout = QVBoxLayout()
    
  4. Now, we'll add three checkboxes and three textboxes...