summaryrefslogtreecommitdiffstats
path: root/python/pyqt/examples3/buttongroups.py
blob: ed2c631502e64e2c85a62d6255f1dc67d585eac3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python
#/****************************************************************************
#** $Id$
#**
#** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
#**
#** This file is part of an example program for Qt.  This example
#** program may be used, distributed and modified without limitation.
#**
#*****************************************************************************/

import sys
from qt import *

TRUE  = 1
FALSE = 0

##
# Creates all child widgets of the ButtonGroups window
##

class ButtonsGroups( QWidget ):
  def __init__( self, *args ):
    apply( QWidget.__init__, (self,) + args )

    # Create Widgets which allow easy layouting
    self.vbox = QVBoxLayout( self, 11, 6 )
    self.box1 = QHBoxLayout( self.vbox )
    self.box2 = QHBoxLayout( self.vbox )

    # ------- first group

    # Create an exclusive button group
    self.grp1 = QButtonGroup( 1, QGroupBox.Horizontal, "Button Group 1 (exclusive)", self )
    self.box1.addWidget( self.grp1 )
    self.grp1.setExclusive( TRUE )

    # insert 3 radiobuttons
    self.rb11 = QRadioButton( "&Radiobutton 1", self.grp1 )
    self.rb11.setChecked( TRUE )
    QRadioButton( "R&adiobutton 2", self.grp1 )
    QRadioButton( "Ra&diobutton 3", self.grp1 )

    # ------- second group

    # Create a non-exclusive buttongroup
    self.grp2 = QButtonGroup( 1, QGroupBox.Horizontal, "Button Group 2 (non-exclusive)", self )
    self.box1.addWidget( self.grp2 )
    self.grp2.setExclusive( FALSE )

    # insert 3 checkboxes
    QCheckBox( "&Checkbox 1", self.grp2 )
    self.cb12 = QCheckBox( "C&heckbox 2", self.grp2 )
    self.cb12.setChecked( TRUE )
    self.cb13 = QCheckBox( "Triple &State Button", self.grp2 )
    self.cb13.setTristate( TRUE )
    self.cb13.setChecked( TRUE )

    # ------------ third group

    # create a buttongroup which is exclusive for radiobuttons and non-exclusive for all other buttons
    self.grp3 = QButtonGroup( 1, QGroupBox.Horizontal, "Button Group 3 (Radiobutton-exclusive)", self )
    self.box2.addWidget( self.grp3 )
    self.grp3.setRadioButtonExclusive( TRUE )

    # insert three radiobuttons
    self.rb21 = QRadioButton( "Rad&iobutton 1", self.grp3 )
    self.rb22 = QRadioButton( "Radi&obutton 2", self.grp3 )
    self.rb23 = QRadioButton( "Radio&button 3", self.grp3 )
    self.rb23.setChecked( TRUE )

    # insert a checkbox...
    self.state = QCheckBox( "E&nable Radiobuttons", self.grp3 )
    self.state.setChecked( TRUE )
    # ...and connect its SIGNAL clicked() with the SLOT slotChangeGrp3State()
    self.connect( self.state, SIGNAL( "clicked()" ), self.slotChangeGrp3State )

    # ------------ fourth group

    # create a groupbox which layouts its childs in a columns
    self.grp4 = QButtonGroup( 1, QGroupBox.Horizontal, "Groupbox with normal buttons", self )
    self.box2.addWidget( self.grp4 )

    # insert two pushbuttons...
    QPushButton( "&Push Button", self.grp4 )
    self.tb2 = QPushButton( "&Toggle Button", self.grp4 )

    # ... and make the second one a toggle button
    self.tb2.setToggleButton( TRUE )
    self.tb2.setOn( TRUE )

    # ... and make the third one a flat button
    self.tb3 = QPushButton( "&Flat Button", self.grp4 )
    self.tb3.setFlat( TRUE )

    # .. and the fourth a button with a menu
    self.tb4 = QPushButton( "Popup Button", self.grp4 )
    menu = QPopupMenu(self.tb4)
    menu.insertItem("Item1", 0)
    menu.insertItem("Item2", 0)
    menu.insertItem("Item3", 0)
    menu.insertItem("Item4", 0)
    self.tb4.setPopup(menu)

    #
    # SLOT slotChangeGrp3State()
    # enables/disables the radiobuttons of the third buttongroup
    #

  def slotChangeGrp3State( self ):
    self.rb21.setEnabled( self.state.isChecked() )
    self.rb22.setEnabled( self.state.isChecked() )
    self.rb23.setEnabled( self.state.isChecked() )


## main program
a = QApplication( sys.argv )

buttonsgroups = ButtonsGroups()
buttonsgroups.resize( 500, 250 )
buttonsgroups.setCaption( "PyQT Example - Buttons and Groups" )
a.setMainWidget( buttonsgroups )
buttonsgroups.show()

a.exec_loop()