SIP4 python bindings for TQt
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

buttongroups.py 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/env python
  2. #/****************************************************************************
  3. #** $Id: buttongroups.py,v 1.1.1.1 2002/06/04 23:04:42 phil Exp $
  4. #**
  5. #** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
  6. #**
  7. #** This file is part of an example program for TQt. This example
  8. #** program may be used, distributed and modified without limitation.
  9. #**
  10. #*****************************************************************************/
  11. import sys
  12. from python_tqt.qt import *
  13. TRUE = 1
  14. FALSE = 0
  15. ##
  16. # Creates all child widgets of the ButtonGroups window
  17. ##
  18. class ButtonsGroups( TQWidget ):
  19. def __init__( self, *args ):
  20. apply( TQWidget.__init__, (self,) + args )
  21. # Create Widgets which allow easy layouting
  22. self.vbox = TQVBoxLayout( self )
  23. self.box1 = TQHBoxLayout( self.vbox )
  24. self.box2 = TQHBoxLayout( self.vbox )
  25. # ------- first group
  26. # Create an exclusive button group
  27. self.grp1 = TQButtonGroup( 1, TQGroupBox.Horizontal, "Button Group 1 (exclusive)", self )
  28. self.box1.addWidget( self.grp1 )
  29. self.grp1.setExclusive( TRUE )
  30. # insert 3 radiobuttons
  31. self.rb11 = TQRadioButton( "&Radiobutton 1", self.grp1 )
  32. self.rb11.setChecked( TRUE )
  33. TQRadioButton( "R&adiobutton 2", self.grp1 )
  34. TQRadioButton( "Ra&diobutton 3", self.grp1 )
  35. # ------- second group
  36. # Create a non-exclusive buttongroup
  37. self.grp2 = TQButtonGroup( 1, TQGroupBox.Horizontal, "Button Group 2 (non-exclusive)", self )
  38. self.box1.addWidget( self.grp2 )
  39. self.grp2.setExclusive( FALSE )
  40. # insert 3 checkboxes
  41. TQCheckBox( "&Checkbox 1", self.grp2 )
  42. self.cb12 = TQCheckBox( "C&heckbox 2", self.grp2 )
  43. self.cb12.setChecked( TRUE )
  44. self.cb13 = TQCheckBox( "Triple &State Button", self.grp2 )
  45. self.cb13.setTristate( TRUE )
  46. self.cb13.setChecked( TRUE )
  47. # ------------ third group
  48. # create a buttongroup which is exclusive for radiobuttons and non-exclusive for all other buttons
  49. self.grp3 = TQButtonGroup( 1, TQGroupBox.Horizontal, "Button Group 3 (Radiobutton-exclusive)", self )
  50. self.box2.addWidget( self.grp3 )
  51. self.grp3.setRadioButtonExclusive( TRUE )
  52. # insert three radiobuttons
  53. self.rb21 = TQRadioButton( "Rad&iobutton 1", self.grp3 )
  54. self.rb22 = TQRadioButton( "Radi&obutton 2", self.grp3 )
  55. self.rb23 = TQRadioButton( "Radio&button 3", self.grp3 )
  56. self.rb23.setChecked( TRUE )
  57. # insert a checkbox...
  58. self.state = TQCheckBox( "E&nable Radiobuttons", self.grp3 )
  59. self.state.setChecked( TRUE )
  60. # ...and connect its SIGNAL clicked() with the SLOT slotChangeGrp3State()
  61. self.connect( self.state, SIGNAL( "clicked()" ), self.slotChangeGrp3State )
  62. # ------------ fourth group
  63. # create a groupbox which layouts its childs in a columns
  64. self.grp4 = TQButtonGroup( 1, TQGroupBox.Horizontal, "Groupbox with normal buttons", self )
  65. self.box2.addWidget( self.grp4 )
  66. # insert two pushbuttons...
  67. TQPushButton( "&Push Button", self.grp4 )
  68. self.tb = TQPushButton( "&Toggle Button", self.grp4 )
  69. # ... and make the second one a toggle button
  70. self.tb.setToggleButton( TRUE )
  71. self.tb.setOn( TRUE )
  72. #
  73. # SLOT slotChangeGrp3State()
  74. # enables/disables the radiobuttons of the third buttongroup
  75. #
  76. def slotChangeGrp3State( self ):
  77. self.rb21.setEnabled( self.state.isChecked() )
  78. self.rb22.setEnabled( self.state.isChecked() )
  79. self.rb23.setEnabled( self.state.isChecked() )
  80. ## main program
  81. a = TQApplication( sys.argv )
  82. buttonsgroups = ButtonsGroups()
  83. buttonsgroups.resize( 500, 250 )
  84. buttonsgroups.setCaption( "Examples for Buttons and Groups" )
  85. a.setMainWidget( buttonsgroups )
  86. buttonsgroups.show()
  87. a.exec_loop()