2016新编Linux窗口程序设计-QT4精彩实例分析实例4使用标准输入框
//inputdialog.h
#ifndef INPUTDLG_H
#define INPUTDLG_H
#include
class InputDlg : public QDialog
{
Q_OBJECT
public:
InputDlg();
public:
QPushButton *nameButton;
QPushButton *sexButton;
QPushButton *ageButton;
QPushButton *statureButton;
QLabel *label1;
QLabel *label2;
QLabel *label3;
QLabel *label4;
QLabel *nameLabel;
QLabel *sexLabel;
QLabel *ageLabel;
QLabel *statureLabel;
private slots:
void slotName();
void slotSex();
void slotAge();
void slotStature();
};
#endif
// inputdialog.cpp
#include "inputdialog.h"
InputDlg::InputDlg()
{
setWindowTitle(tr("Input Dialog"));
label1 = new QLabel(tr("Name : "));
label2 = new QLabel(tr("Sex : "));
label3 = new QLabel(tr("Age : "));
label4 = new QLabel(tr("Stature : "));
nameLabel = new QLabel(tr("LiMing"));
nameLabel->setFrameStyle(QFrame::Panel|QFrame::Sunken);
sexLabel = new QLabel(tr("male"));
sexLabel->setFrameStyle(QFrame::Panel|QFrame::Sunken);
ageLabel = new QLabel(tr("25"));
ageLabel->setFrameStyle(QFrame::Panel|QFrame::Sunken);
statureLabel = new QLabel("175.5");
statureLabel->setFrameStyle(QFrame::Panel|QFrame::Sunken);
nameButton = new QPushButton;
nameButton->setIcon(QIcon(":/images/btn.png"));
sexButton = new QPushButton;
sexButton->setIcon(QIcon(":/images/btn.png"));
ageButton = new QPushButton;
ageButton->setIcon(QIcon(":/images/btn.png"));
statureButton = new QPushButton;
statureButton->setIcon(QIcon(":/images/btn.png"));
QGridLayout *layout = new QGridLayout( this );
int name = 0;
int sex = 1;
int age = 2;
int stature = 3;
layout->addWidget( label1, name, 0 );
layout->addWidget( nameLabel, name, 1 );
layout->addWidget( nameButton, name, 2 );
layout->addWidget( label2, sex, 0 );
layout->addWidget( sexLabel, sex, 1 );
layout->addWidget( sexButton, sex, 2 );
layout->addWidget( label