PYQT4 Radio Box Qcheckbox

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.