Parts in the PYQT4
A part is the underlying element that builds an application. The PYQT4 kit has a large variety of components. For example: Buttons, radio boxes, sliders, list boxes, and so on, any programmer will need to complete their work.
Qcheckbox Radio Box
A radio box has two states: selected or unchecked. It looks like a label with an attached attachment. When the user selects or cancels the selection, a statechanged () signal is sent by the radio box.
#!/usr/bin/python#-*-coding:utf-8-*-ImportSYS fromPyQt4ImportQtgui, QtcoreclassCheckBox (qtgui.qwidget):def __init__(Self, parent =None): Qtgui.qwidget.__init__(self, parent) Self.setgeometry (300, 300, 250, 150) Self.setwindowtitle ('Checkbox') SELF.CB= Qtgui.qcheckbox ('Show title', self) self.cb.setFocusPolicy (QtCore.Qt.NoFocus) self.cb.move (10, 10) Self.cb.toggle () Self.connect (SELF.CB, Qtcore.signal ('statechanged (int)'), Self.changetitle)defChangetitle (self, value):ifself.cb.isChecked (): Self.setwindowtitle ('Checkbox') Else: Self.setwindowtitle ('unchecked') App=qtgui.qapplication (SYS.ARGV) CB=CheckBox () cb.show () Sys.exit (App.exec_ ())
Effect:
In this example, we have created a radio box to change the window caption.
SELF.CB = Qtgui.qcheckbox (' Show title ', self)
This statement is used to create a single box with the label information ' Show Tile '.
Self.connect (SELF.CB, Qtcore.signal (' statechanged (int) '), Self.changetitle)
Here we connect the user-defined Changetitle () function to the statechanged () signal of the Radio box. The custom Changetitle () function resets the window's caption.
Self.cb.setFocusPolicy (QtCore.Qt.NoFocus)
By default, the Radio box is focused, and the highlighted form is a single-box label that is covered by a thin rectangle. This rectangle looks a bit too serious, so we use the above code to modify the focus style of the radio box to Qt.nofocus's unfocused style.
Self.cb.toggle ()
In the initial state we set the caption of the window, so we need to use the above code line to select the Radio box. By default, a radio box is not selected.
PYQT4 Radio Box Qcheckbox