source: trunk/examples/buttongroups/buttongroups.cpp@ 10

Last change on this file since 10 was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
1/****************************************************************************
2** $Id: buttongroups.cpp 2 2005-11-16 15:49:26Z dmik $
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 <qpopupmenu.h>
14#include <qbuttongroup.h>
15#include <qlayout.h>
16#include <qradiobutton.h>
17#include <qcheckbox.h>
18#include <qgroupbox.h>
19#include <qpushbutton.h>
20
21/*
22 * Constructor
23 *
24 * Creates all child widgets of the ButtonGroups window
25 */
26
27ButtonsGroups::ButtonsGroups( QWidget *parent, const char *name )
28 : QWidget( parent, name )
29{
30 // Create Widgets which allow easy layouting
31 QVBoxLayout *vbox = new QVBoxLayout( this, 11, 6 );
32 QHBoxLayout *box1 = new QHBoxLayout( vbox );
33 QHBoxLayout *box2 = new QHBoxLayout( vbox );
34
35 // ------- first group
36
37 // Create an exclusive button group
38 QButtonGroup *bgrp1 = new QButtonGroup( 1, QGroupBox::Horizontal, "Button Group 1 (exclusive)", this);
39 box1->addWidget( bgrp1 );
40 bgrp1->setExclusive( TRUE );
41
42 // insert 3 radiobuttons
43 QRadioButton *rb11 = new QRadioButton( "&Radiobutton 1", bgrp1 );
44 rb11->setChecked( TRUE );
45 (void)new QRadioButton( "R&adiobutton 2", bgrp1 );
46 (void)new QRadioButton( "Ra&diobutton 3", bgrp1 );
47
48 // ------- second group
49
50 // Create a non-exclusive buttongroup
51 QButtonGroup *bgrp2 = new QButtonGroup( 1, QGroupBox::Horizontal, "Button Group 2 (non-exclusive)", this );
52 box1->addWidget( bgrp2 );
53 bgrp2->setExclusive( FALSE );
54
55 // insert 3 checkboxes
56 (void)new QCheckBox( "&Checkbox 1", bgrp2 );
57 QCheckBox *cb12 = new QCheckBox( "C&heckbox 2", bgrp2 );
58 cb12->setChecked( TRUE );
59 QCheckBox *cb13 = new QCheckBox( "Triple &State Button", bgrp2 );
60 cb13->setTristate( TRUE );
61 cb13->setChecked( TRUE );
62
63 // ------------ third group
64
65 // create a buttongroup which is exclusive for radiobuttons and non-exclusive for all other buttons
66 QButtonGroup *bgrp3 = new QButtonGroup( 1, QGroupBox::Horizontal, "Button Group 3 (Radiobutton-exclusive)", this );
67 box2->addWidget( bgrp3 );
68 bgrp3->setRadioButtonExclusive( TRUE );
69
70 // insert three radiobuttons
71 rb21 = new QRadioButton( "Rad&iobutton 1", bgrp3 );
72 rb22 = new QRadioButton( "Radi&obutton 2", bgrp3 );
73 rb23 = new QRadioButton( "Radio&button 3", bgrp3 );
74 rb23->setChecked( TRUE );
75
76 // insert a checkbox...
77 state = new QCheckBox( "E&nable Radiobuttons", bgrp3 );
78 state->setChecked( TRUE );
79 // ...and connect its SIGNAL clicked() with the SLOT slotChangeGrp3State()
80 connect( state, SIGNAL( clicked() ), this, SLOT( slotChangeGrp3State() ) );
81
82 // ------------ fourth group
83
84 // create a groupbox which layouts its childs in a columns
85 QGroupBox *bgrp4 = new QButtonGroup( 1, QGroupBox::Horizontal, "Groupbox with normal buttons", this );
86 box2->addWidget( bgrp4 );
87
88 // insert four pushbuttons...
89 (void)new QPushButton( "&Push Button", bgrp4, "push" );
90
91 // now make the second one a toggle button
92 QPushButton *tb2 = new QPushButton( "&Toggle Button", bgrp4, "toggle" );
93 tb2->setToggleButton( TRUE );
94 tb2->setOn( TRUE );
95
96 // ... and make the third one a flat button
97 QPushButton *tb3 = new QPushButton( "&Flat Button", bgrp4, "flat" );
98 tb3->setFlat(TRUE);
99
100 // .. and the fourth a button with a menu
101 QPushButton *tb4 = new QPushButton( "Popup Button", bgrp4, "popup" );
102 QPopupMenu *menu = new QPopupMenu(tb4);
103 menu->insertItem("Item1", 0);
104 menu->insertItem("Item2", 1);
105 menu->insertItem("Item3", 2);
106 menu->insertItem("Item4", 3);
107 tb4->setPopup(menu);
108}
109
110/*
111 * SLOT slotChangeGrp3State()
112 *
113 * enables/disables the radiobuttons of the third buttongroup
114 */
115
116void ButtonsGroups::slotChangeGrp3State()
117{
118 rb21->setEnabled( state->isChecked() );
119 rb22->setEnabled( state->isChecked() );
120 rb23->setEnabled( state->isChecked() );
121}
Note: See TracBrowser for help on using the repository browser.