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 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/usr/bin/env python
  2. #/****************************************************************************
  3. #** $Id: buttongroups.py,v 1.2 2002/12/20 18:46:10 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, 11, 6 )
  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.tb2 = TQPushButton( "&Toggle Button", self.grp4 )
  69. # ... and make the second one a toggle button
  70. self.tb2.setToggleButton( TRUE )
  71. self.tb2.setOn( TRUE )
  72. # ... and make the third one a flat button
  73. self.tb3 = TQPushButton( "&Flat Button", self.grp4 )
  74. self.tb3.setFlat( TRUE )
  75. # .. and the fourth a button with a menu
  76. self.tb4 = TQPushButton( "Popup Button", self.grp4 )
  77. menu = TQPopupMenu(self.tb4)
  78. menu.insertItem("Item1", 0)
  79. menu.insertItem("Item2", 0)
  80. menu.insertItem("Item3", 0)
  81. menu.insertItem("Item4", 0)
  82. self.tb4.setPopup(menu)
  83. #
  84. # SLOT slotChangeGrp3State()
  85. # enables/disables the radiobuttons of the third buttongroup
  86. #
  87. def slotChangeGrp3State( self ):
  88. self.rb21.setEnabled( self.state.isChecked() )
  89. self.rb22.setEnabled( self.state.isChecked() )
  90. self.rb23.setEnabled( self.state.isChecked() )
  91. ## main program
  92. a = TQApplication( sys.argv )
  93. buttonsgroups = ButtonsGroups()
  94. buttonsgroups.resize( 500, 250 )
  95. buttonsgroups.setCaption( "PyQT Example - Buttons and Groups" )
  96. a.setMainWidget( buttonsgroups )
  97. buttonsgroups.show()
  98. a.exec_loop()