Home arrow Python arrow Page 2 - PyQT: Input Widgets

QCheckBox - Python

You may have experienced some headaches in the past when creating GUIs to gather user input. Python makes this process easy with input widgets. Keep reading to learn more.

  1. PyQT: Input Widgets
  2. QCheckBox
  3. PyQT in the Real World
  4. The Connections
  5. The Main Part
By: A.P.Rajshekhar
Rating: starstarstarstarstar / 4
November 20, 2006

print this article



This widget provides the checkbox with text. It can have three states – checked, unchecked and no change of state. In essence it is an option button that can be turned on or off. In an application checkbox it can come handy when a set of options have to be presented to the user and user has the choice of selecting one or more options.

Typically checkboxes are used when their state doesn’t effect the states of other widgets. However there are exceptions to this rule as we will see in the example. The main aspect of QCheckBox is that just like QButton, it also has been derived from QAbstractButton and doesn’t have any slots. However, the methods provide all the required services. Secondly, a group of logically similar checkboxes can be grouped visually into a category using the QButtonGroup. The main signal of QCheckbox is stateChange(), and its main methods are checkStateSet() and setText(). The second method is inherited. 

The stateChange() signal is used whenever the user checks or unchecks the widget. In other words, when the state of the widget changes, the widget emits a stateChange signal. The argument contains the check box’s new Toggle state. The Toggle state is an integer that contains current state.

The checkStateSet() method takes Qt.CheckState as argument. The valid values are Qt.Unchecked, Qt.PartiallyChecked and Qt.Checked. The second value comes into the picture when items in hierarchical models may be partially checked if some, but not all, of their children are checked.

The setText() method can be used to set the text of a checkbox. The parameter passed is QString, representing the text to be set. However, it doesn’t cause any signals to be emitted. Using the setIcon method, an icon can be placed beside the checkbox.

To create a checkbox with the text "secure," the code would be:


That brings us to the end of this section. In the next section I would be designing a form that would provide minimal connection details to connect to a server.

>>> More Python Articles          >>> More By A.P.Rajshekhar

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- Tuples and Other Python Object Types
- The Dictionary Python Object Type
- String and List Python Object Types
- Introducing Python Object Types
- Mobile Programming using PyS60: Advanced UI ...
- Nested Functions in Python
- Python Parameters, Functions and Arguments
- Python Statements and Functions
- Statements and Iterators in Python

Developer Shed Affiliates


Dev Shed Tutorial Topics: