diff options
author | Timothy Pearson <[email protected]> | 2011-07-10 15:24:15 -0500 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2011-07-10 15:24:15 -0500 |
commit | bd0f3345a938b35ce6a12f6150373b0955b8dd12 (patch) | |
tree | 7a520322212d48ebcb9fbe1087e7fca28b76185c /examples/buttongroups | |
download | qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.tar.gz qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.zip |
Add Qt3 development HEAD version
Diffstat (limited to 'examples/buttongroups')
-rw-r--r-- | examples/buttongroups/README | 13 | ||||
-rw-r--r-- | examples/buttongroups/buttongroups.cpp | 120 | ||||
-rw-r--r-- | examples/buttongroups/buttongroups.doc | 27 | ||||
-rw-r--r-- | examples/buttongroups/buttongroups.h | 34 | ||||
-rw-r--r-- | examples/buttongroups/buttongroups.pro | 10 | ||||
-rw-r--r-- | examples/buttongroups/main.cpp | 24 |
6 files changed, 228 insertions, 0 deletions
diff --git a/examples/buttongroups/README b/examples/buttongroups/README new file mode 100644 index 0000000..f975396 --- /dev/null +++ b/examples/buttongroups/README @@ -0,0 +1,13 @@ +This example program shows how to use + + - different types of buttons + - different types of groupboxes + +The buttons which are used are radiobuttons, checkboxes (also tristate +checkboxes), normal pusbuttons and toggleable pushbuttons. These +buttons are seperated in four groups using groupboxes. The example +shows how to make a buttongroup totally exclusive (only one button can +be checked), exclusive for radiobuttons only or non-exclusive. It +also demonstrates how buttons (and other widgets) can be laid out +in rows and columns using a groupbox. + diff --git a/examples/buttongroups/buttongroups.cpp b/examples/buttongroups/buttongroups.cpp new file mode 100644 index 0000000..dc5785f --- /dev/null +++ b/examples/buttongroups/buttongroups.cpp @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include "buttongroups.h" + +#include <qpopupmenu.h> +#include <qbuttongroup.h> +#include <qlayout.h> +#include <qradiobutton.h> +#include <qcheckbox.h> +#include <qgroupbox.h> +#include <qpushbutton.h> + +/* + * Constructor + * + * Creates all child widgets of the ButtonGroups window + */ + +ButtonsGroups::ButtonsGroups( QWidget *parent, const char *name ) + : QWidget( parent, name ) +{ + // Create Widgets which allow easy layouting + QVBoxLayout *vbox = new QVBoxLayout( this, 11, 6 ); + QHBoxLayout *box1 = new QHBoxLayout( vbox ); + QHBoxLayout *box2 = new QHBoxLayout( vbox ); + + // ------- first group + + // Create an exclusive button group + QButtonGroup *bgrp1 = new QButtonGroup( 1, QGroupBox::Horizontal, "Button Group 1 (exclusive)", this); + box1->addWidget( bgrp1 ); + bgrp1->setExclusive( TRUE ); + + // insert 3 radiobuttons + QRadioButton *rb11 = new QRadioButton( "&Radiobutton 1", bgrp1 ); + rb11->setChecked( TRUE ); + (void)new QRadioButton( "R&adiobutton 2", bgrp1 ); + (void)new QRadioButton( "Ra&diobutton 3", bgrp1 ); + + // ------- second group + + // Create a non-exclusive buttongroup + QButtonGroup *bgrp2 = new QButtonGroup( 1, QGroupBox::Horizontal, "Button Group 2 (non-exclusive)", this ); + box1->addWidget( bgrp2 ); + bgrp2->setExclusive( FALSE ); + + // insert 3 checkboxes + (void)new QCheckBox( "&Checkbox 1", bgrp2 ); + QCheckBox *cb12 = new QCheckBox( "C&heckbox 2", bgrp2 ); + cb12->setChecked( TRUE ); + QCheckBox *cb13 = new QCheckBox( "Triple &State Button", bgrp2 ); + cb13->setTristate( TRUE ); + cb13->setChecked( TRUE ); + + // ------------ third group + + // create a buttongroup which is exclusive for radiobuttons and non-exclusive for all other buttons + QButtonGroup *bgrp3 = new QButtonGroup( 1, QGroupBox::Horizontal, "Button Group 3 (Radiobutton-exclusive)", this ); + box2->addWidget( bgrp3 ); + bgrp3->setRadioButtonExclusive( TRUE ); + + // insert three radiobuttons + rb21 = new QRadioButton( "Rad&iobutton 1", bgrp3 ); + rb22 = new QRadioButton( "Radi&obutton 2", bgrp3 ); + rb23 = new QRadioButton( "Radio&button 3", bgrp3 ); + rb23->setChecked( TRUE ); + + // insert a checkbox... + state = new QCheckBox( "E&nable Radiobuttons", bgrp3 ); + state->setChecked( TRUE ); + // ...and connect its SIGNAL clicked() with the SLOT slotChangeGrp3State() + connect( state, SIGNAL( clicked() ), this, SLOT( slotChangeGrp3State() ) ); + + // ------------ fourth group + + // create a groupbox which layouts its childs in a columns + QGroupBox *bgrp4 = new QButtonGroup( 1, QGroupBox::Horizontal, "Groupbox with normal buttons", this ); + box2->addWidget( bgrp4 ); + + // insert four pushbuttons... + (void)new QPushButton( "&Push Button", bgrp4, "push" ); + + // now make the second one a toggle button + QPushButton *tb2 = new QPushButton( "&Toggle Button", bgrp4, "toggle" ); + tb2->setToggleButton( TRUE ); + tb2->setOn( TRUE ); + + // ... and make the third one a flat button + QPushButton *tb3 = new QPushButton( "&Flat Button", bgrp4, "flat" ); + tb3->setFlat(TRUE); + + // .. and the fourth a button with a menu + QPushButton *tb4 = new QPushButton( "Popup Button", bgrp4, "popup" ); + QPopupMenu *menu = new QPopupMenu(tb4); + menu->insertItem("Item1", 0); + menu->insertItem("Item2", 1); + menu->insertItem("Item3", 2); + menu->insertItem("Item4", 3); + tb4->setPopup(menu); +} + +/* + * SLOT slotChangeGrp3State() + * + * enables/disables the radiobuttons of the third buttongroup + */ + +void ButtonsGroups::slotChangeGrp3State() +{ + rb21->setEnabled( state->isChecked() ); + rb22->setEnabled( state->isChecked() ); + rb23->setEnabled( state->isChecked() ); +} diff --git a/examples/buttongroups/buttongroups.doc b/examples/buttongroups/buttongroups.doc new file mode 100644 index 0000000..439cce7 --- /dev/null +++ b/examples/buttongroups/buttongroups.doc @@ -0,0 +1,27 @@ +/* +*/ +/*! \page buttongroups-example.html + + \ingroup examples + \title Buttons and Groupboxes + + This example shows different types of groupboxes (buttongroups, etc.) and + different kinds of buttons (checkboxes, radiobuttons, pushbuttons, etc.). + + <hr> + + Header file: + + \include buttongroups/buttongroups.h + + <hr> + + Implementation: + + \include buttongroups/buttongroups.cpp + + <hr> + + Main: + \include buttongroups/main.cpp +*/ diff --git a/examples/buttongroups/buttongroups.h b/examples/buttongroups/buttongroups.h new file mode 100644 index 0000000..271cce3 --- /dev/null +++ b/examples/buttongroups/buttongroups.h @@ -0,0 +1,34 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#ifndef BUTTONS_GROUPS_H +#define BUTTONS_GROUPS_H + +#include <qwidget.h> + +class QCheckBox; +class QRadioButton; + +class ButtonsGroups : public QWidget +{ + Q_OBJECT + +public: + ButtonsGroups( QWidget *parent = 0, const char *name = 0 ); + +protected: + QCheckBox *state; + QRadioButton *rb21, *rb22, *rb23; + +protected slots: + void slotChangeGrp3State(); + +}; + +#endif diff --git a/examples/buttongroups/buttongroups.pro b/examples/buttongroups/buttongroups.pro new file mode 100644 index 0000000..cfad62e --- /dev/null +++ b/examples/buttongroups/buttongroups.pro @@ -0,0 +1,10 @@ +TEMPLATE = app +TARGET = buttongroups + +CONFIG += qt warn_on release + +REQUIRES = small-config + +HEADERS = buttongroups.h +SOURCES = buttongroups.cpp \ + main.cpp diff --git a/examples/buttongroups/main.cpp b/examples/buttongroups/main.cpp new file mode 100644 index 0000000..7f117f0 --- /dev/null +++ b/examples/buttongroups/main.cpp @@ -0,0 +1,24 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include "buttongroups.h" +#include <qapplication.h> + +int main( int argc, char **argv ) +{ + QApplication a( argc, argv ); + + ButtonsGroups buttonsgroups; + buttonsgroups.resize( 500, 250 ); + buttonsgroups.setCaption( "Qt Example - Buttongroups" ); + a.setMainWidget( &buttonsgroups ); + buttonsgroups.show(); + + return a.exec(); +} |