home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / examples / buttongroups / buttongroups.cpp < prev    next >
C/C++ Source or Header  |  2001-10-11  |  4KB  |  112 lines

  1. /****************************************************************************
  2. ** $Id:  qt/buttongroups.cpp   3.0.0   edited Sep 12 17:29 $
  3. **
  4. ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
  5. **
  6. ** This file is part of an example program for Qt.  This example
  7. ** program may be used, distributed and modified without limitation.
  8. **
  9. *****************************************************************************/
  10.  
  11. #include "buttongroups.h"
  12.  
  13. #include <qbuttongroup.h>
  14. #include <qlayout.h>
  15. #include <qradiobutton.h>
  16. #include <qcheckbox.h>
  17. #include <qgroupbox.h>
  18. #include <qpushbutton.h>
  19.  
  20. /*
  21.  * Constructor
  22.  *
  23.  * Creates all child widgets of the ButtonGroups window
  24.  */
  25.  
  26. ButtonsGroups::ButtonsGroups( QWidget *parent, const char *name )
  27.     : QWidget( parent, name )
  28. {
  29.     // Create Widgets which allow easy layouting
  30.     QVBoxLayout *vbox = new QVBoxLayout( this );
  31.     QHBoxLayout *box1 = new QHBoxLayout( vbox );
  32.     QHBoxLayout *box2 = new QHBoxLayout( vbox );
  33.  
  34.     // ------- first group
  35.  
  36.     // Create an exclusive button group
  37.     QButtonGroup *bgrp1 = new QButtonGroup( 1, QGroupBox::Horizontal, "Button Group 1 (exclusive)", this);
  38.     box1->addWidget( bgrp1 );
  39.     bgrp1->setExclusive( TRUE );
  40.  
  41.     // insert 3 radiobuttons
  42.     QRadioButton *rb11 = new QRadioButton( "&Radiobutton 1", bgrp1 );
  43.     rb11->setChecked( TRUE );
  44.     (void)new QRadioButton( "R&adiobutton 2", bgrp1 );
  45.     (void)new QRadioButton( "Ra&diobutton 3", bgrp1 );
  46.  
  47.     // ------- second group
  48.  
  49.     // Create a non-exclusive buttongroup
  50.     QButtonGroup *bgrp2 = new QButtonGroup( 1, QGroupBox::Horizontal, "Button Group 2 (non-exclusive)", this );
  51.     box1->addWidget( bgrp2 );
  52.     bgrp2->setExclusive( FALSE );
  53.  
  54.     // insert 3 checkboxes
  55.     (void)new QCheckBox( "&Checkbox 1", bgrp2 );
  56.     QCheckBox *cb12 = new QCheckBox( "C&heckbox 2", bgrp2 );
  57.     cb12->setChecked( TRUE );
  58.     QCheckBox *cb13 = new QCheckBox( "Triple &State Button", bgrp2 );
  59.     cb13->setTristate( TRUE );
  60.     cb13->setChecked( TRUE );
  61.  
  62.     // ------------ third group
  63.  
  64.     // create a buttongroup which is exclusive for radiobuttons and non-exclusive for all other buttons
  65.     QButtonGroup *bgrp3 = new QButtonGroup( 1, QGroupBox::Horizontal, "Button Group 3 (Radiobutton-exclusive)", this );
  66.     box2->addWidget( bgrp3 );
  67.     bgrp3->setRadioButtonExclusive( TRUE );
  68.  
  69.     // insert three radiobuttons
  70.     rb21 = new QRadioButton( "Rad&iobutton 1", bgrp3 );
  71.     rb22 = new QRadioButton( "Radi&obutton 2", bgrp3 );
  72.     rb23 = new QRadioButton( "Radio&button 3", bgrp3 );
  73.     rb23->setChecked( TRUE );
  74.  
  75.     // insert a checkbox...
  76.     state = new QCheckBox( "E&nable Radiobuttons", bgrp3 );
  77.     state->setChecked( TRUE );
  78.     // ...and connect its SIGNAL clicked() with the SLOT slotChangeGrp3State()
  79.     connect( state, SIGNAL( clicked() ), this, SLOT( slotChangeGrp3State() ) );
  80.  
  81.     // ------------ fourth group
  82.  
  83.     // create a groupbox which layouts its childs in a columns
  84.     QGroupBox *bgrp4 = new QButtonGroup( 1, QGroupBox::Horizontal, "Groupbox with normal buttons", this );
  85.     box2->addWidget( bgrp4 );
  86.  
  87.     // insert three pushbuttons...
  88.     (void)new QPushButton( "&Push Button", bgrp4 );
  89.     QPushButton *tb2 = new QPushButton( "&Toggle Button", bgrp4 );
  90.     QPushButton *tb3 = new QPushButton( "&Flat Button", bgrp4 );
  91.  
  92.     // ... and make the second one a toggle button
  93.     tb2->setToggleButton( TRUE );
  94.     tb2->setOn( TRUE );
  95.  
  96.     // ... and make the third one a flat button
  97.     tb3->setFlat(TRUE);
  98. }
  99.  
  100. /*
  101.  * SLOT slotChangeGrp3State()
  102.  *
  103.  * enables/disables the radiobuttons of the third buttongroup
  104.  */
  105.  
  106. void ButtonsGroups::slotChangeGrp3State()
  107. {
  108.     rb21->setEnabled( state->isChecked() );
  109.     rb22->setEnabled( state->isChecked() );
  110.     rb23->setEnabled( state->isChecked() );
  111. }
  112.