Information on using Designer can be found in Chapter 26. The figures appear to use a slightly different version of Designer than what's on fenris.

Select Dialog.

Default Dialog Layout.

Open the Display tab and Select TextLabel and click on the Form.

Use the Object Hierarchy to change the names of the Form1 and textLabel1. Resize the label. Size the Form as a .ui file.

Display of screen after creating radio buttons and button group and quit button. Also changing properties.

Click on the connection point to change from arrow mode to connection mode. Drag the quit button onto the form indicating that you want to connect a quit button signal to a form slot.

Add slots to the text label to accept changed in gender.

Create a header and source code using

uic –o frmclickme.h frmclickme.ui

uic –o frmclickme.cpp –impl frmclickme.h frmclickme.ui

These files have a skeleton of the slot, but is not connected.

frmclickme.h:

/****************************************************************************

** Form interface generated from reading ui file 'frmclickme.ui'

**

** Created: Mon Mar 8 11:14:06 2004

** by: The User Interface Compiler ($Id: qt/main.cpp 3.1.1 edited Nov 21 17:40 $)

**

** WARNING! All changes made in this file will be lost!

****************************************************************************/

#ifndef FRMCLICKME_H

#define FRMCLICKME_H

#include <qvariant.h>

#include <qdialog.h>

class QVBoxLayout;

class QHBoxLayout;

class QGridLayout;

class QButtonGroup;

class QLabel;

class QPushButton;

class QRadioButton;

class frmClickMe : public QDialog

{

Q_OBJECT

public:

frmClickMe( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );

~frmClickMe();

QPushButton* btnQuit;

QButtonGroup* btnGrpGender;

QRadioButton* radBtnFemale;

QRadioButton* radBtnMale;

QLabel* txtLblMessage;

public slots:

virtual void updateGender(bool);

protected:

protected slots:

virtual void languageChange();

};

#endif // FRMCLICKME_H

frmclickme.cpp:

/****************************************************************************

** Form implementation generated from reading ui file 'frmclickme.ui'

**

** Created: Mon Mar 8 11:14:26 2004

** by: The User Interface Compiler ($Id: qt/main.cpp 3.1.1 edited Nov 21 17:40 $)

**

** WARNING! All changes made in this file will be lost!

****************************************************************************/

#include "frmclickme.h"

#include <qvariant.h>

#include <qbuttongroup.h>

#include <qlabel.h>

#include <qpushbutton.h>

#include <qradiobutton.h>

#include <qlayout.h>

#include <qtooltip.h>

#include <qwhatsthis.h>

/*

* Constructs a frmClickMe as a child of 'parent', with the

* name 'name' and widget flags set to 'f'.

*

* The dialog will by default be modeless, unless you set 'modal' to

* TRUE to construct a modal dialog.

*/

frmClickMe::frmClickMe( QWidget* parent, const char* name, bool modal, WFlags fl )

: QDialog( parent, name, modal, fl )

{

if ( !name )

setName( "frmClickMe" );

btnQuit = new QPushButton( this, "btnQuit" );

btnQuit->setGeometry( QRect( 500, 430, 82, 25 ) );

btnGrpGender = new QButtonGroup( this, "btnGrpGender" );

btnGrpGender->setGeometry( QRect( 40, 100, 131, 111 ) );

radBtnFemale = new QRadioButton( btnGrpGender, "radBtnFemale" );

radBtnFemale->setGeometry( QRect( 30, 70, 82, 20 ) );

radBtnMale = new QRadioButton( btnGrpGender, "radBtnMale" );

radBtnMale->setGeometry( QRect( 30, 30, 82, 20 ) );

txtLblMessage = new QLabel( this, "txtLblMessage" );

txtLblMessage->setGeometry( QRect( 30, 50, 540, 30 ) );

languageChange();

resize( QSize(600, 480).expandedTo(minimumSizeHint()) );

// signals and slots connections

connect( btnQuit, SIGNAL( clicked() ), this, SLOT( close() ) );

connect( radBtnMale, SIGNAL( toggled(bool) ), this, SLOT( updateGender(bool) ) );

}

/*

* Destroys the object and frees any allocated resources

*/

frmClickMe::~frmClickMe()

{

// no need to delete child widgets, Qt does it all for us

}

/*

* Sets the strings of the subwidgets using the current

* language.

*/

void frmClickMe::languageChange()

{

setCaption( tr( "Click Me" ) );

btnQuit->setText( tr( "Quit" ) );

btnGrpGender->setTitle( tr( "Gender" ) );

radBtnFemale->setText( tr( "Female" ) );

radBtnMale->setText( tr( "Male" ) );

txtLblMessage->setText( QString::null );

}

void frmClickMe::updateGender(bool)

{

qWarning( "frmClickMe::updateGender(bool): Not implemented yet" );

}

We wish to create an implementation of the form using frmclickme as the base class. Create a skeleton of the implementation using the subclass syntax

uic –o frmclickmeimpl.h –subdecl frmclickmeimpl frmclickme.h frmclickme.ui

cp frmclickmeimpl.h frmclickme.cpp and edit.

frmclickmeimpl.h:

#ifndef FRMCLICKMEIMPL_H

#define FRMCLICKMEIMPL_H

#include "frmclickme.h"

class frmclickmeimpl : public frmClickMe

{

Q_OBJECT

public:

frmclickmeimpl( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );

~frmclickmeimpl();

public slots:

void updateGender(bool);

};

#endif // FRMCLICKMEIMPL_H

frmclickmeimp.cpp:

#include "frmclickmeimpl.h"

#include <qlabel.h>

#include <qvariant.h>

#include <qwhatsthis.h>

frmclickmeimpl::frmclickmeimpl(

QWidget* parent,

const char* name,

bool modal,

WFlags fl) :

frmClickMe(parent, name, modal, fl)

{

};

frmclickmeimpl::~frmclickmeimpl(){}

void frmclickmeimpl::updateGender(bool MaleSelected)

{

// Update the label based on the selected Gender

if (MaleSelected)

txtLblMessage->setText("Male Selected");

else

txtLblMessage->setText("Female Selected");

}

project.cpp:

#include <qapplication.h>

#include "frmclickmeimpl.h"

int main(int argc, char* argv[] )

{

QApplication app(argc, argv);

frmclickmeimpl frmclickme(0, "Click Me", true);

app.setMainWidget( &frmclickme );

int ret = frmclickme.exec();

return ret;

}