Qt标准输入框

北战南征 提交于 2020-03-08 00:57:16

//inputdlg.h

#ifndef INPUTDLG_H
#define INPUTDLG_H

#include <QDialog>
#include <QLabel>
#include <QPushButton>
#include <QGridLayout>
#include <QDialog>

class InputDlg : public QDialog
{
    Q_OBJECT

public:
    InputDlg(QWidget *parent = 0);
    ~InputDlg();

private slots:
    void ChangeName();
    void ChangeSex();
    void ChangeAge();
    void ChangeScore();

private:
    QLabel *nameLabel1;
    QLabel *sexLabel1;
    QLabel *ageLabel1;
    QLabel *scoreLabel1;
    QLabel *nameLabel2;
    QLabel *sexLabel2;
    QLabel *ageLabel2;
    QLabel *scoreLabel2;
    QPushButton *nameBtn;
    QPushButton *sexBtn;
    QPushButton *ageBtn;
    QPushButton *scoreBtn;
    QGridLayout *mainLayout;
};
#endif // INPUTDLG_H

//inputdlg.cpp

#include "inputdlg.h"

InputDlg::InputDlg(QWidget *parent)
    : QDialog(parent)
{
    setWindowTitle(tr("标准输入对话框"));
    nameLabel1 = new QLabel;
    nameLabel1->setText(tr("姓名:"));
    nameLabel2  = new QLabel;
    nameLabel2->setText(tr("李伟夫"));
    nameLabel2->setFrameStyle(QFrame::Panel|QFrame::Sunken);
    nameBtn = new  QPushButton;
    nameBtn->setText(tr("修改名字"));

    sexLabel1 = new QLabel;
    sexLabel1->setText(tr("性别:"));
    sexLabel2 = new QLabel;
    sexLabel2->setText(tr("男"));
    sexLabel2->setFrameStyle(QFrame::Panel|QFrame::Sunken);
    sexBtn = new QPushButton;
    sexBtn->setText(tr("修改性别"));

    ageLabel1 = new QLabel;
    ageLabel1->setText(tr("年龄:"));
    ageLabel2 = new QLabel;
    ageLabel2->setText(tr("21"));
    ageLabel2->setFrameStyle(QFrame::Panel|QFrame::Sunken);
    ageBtn = new QPushButton;
    ageBtn->setText(tr("修改年龄"));

    scoreLabel1 = new QLabel;
    scoreLabel1->setText(tr("成绩:"));
    scoreLabel2 = new QLabel;
    scoreLabel2->setText(tr("80"));
    scoreLabel2->setFrameStyle(QFrame::Panel|QFrame::Sunken);
    scoreBtn = new QPushButton;
    scoreBtn->setText(tr("修改成绩"));

    mainLayout = new QGridLayout(this);
    mainLayout->addWidget(nameLabel1,0,0);
    mainLayout->addWidget(nameLabel2,0,1);
    mainLayout->addWidget(nameBtn,0,2);

    mainLayout->addWidget(sexLabel1,1,0);
    mainLayout->addWidget(sexLabel2,1,1);
    mainLayout->addWidget(sexBtn,1,2);

    mainLayout->addWidget(ageLabel1,2,0);
    mainLayout->addWidget(ageLabel2,2,1);
    mainLayout->addWidget(ageBtn,2,2);

    mainLayout->addWidget(scoreLabel1,3,0);
    mainLayout->addWidget(scoreLabel2,3,1);
    mainLayout->addWidget(scoreBtn,3,2);

    connect(nameBtn,SIGNAL(clicked()),this,SLOT(ChangeName()));
    connect(sexBtn,SIGNAL(clicked()),this,SLOT(ChangeSex()));
    connect(ageBtn,SIGNAL(clicked()),this,SLOT(ChangeAge()));
    connect(scoreBtn,SIGNAL(clicked()),this,SLOT(ChangeScore()));
}


InputDlg::~InputDlg()
{

}
void InputDlg::ChangeName()
{

}
void InputDlg::ChangeSex()
{

}
void InputDlg::ChangeAge()
{

}
void InputDlg::ChangeScore()
{

}

//dialog.h

#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>
#include "inputdlg.h"

class Dialog : public QDialog
{
    Q_OBJECT

public:
    Dialog(QWidget *parent = 0);
    ~Dialog();

private:
    QPushButton *inputBtn;
    InputDlg *inputDlg;

private slots:
    void showInput();
};

#endif // DIALOG_H

//dialog.cpp

#include "dialog.h"

Dialog::Dialog(QWidget *parent)
    : QDialog(parent)
{

    inputBtn = new QPushButton;
    inputBtn->setText(tr("标准输入对话框"));

    QGridLayout *main = new QGridLayout(this);
    main->addWidget(inputBtn,3,0);

    connect(inputBtn,SIGNAL(clicked()),this,SLOT(showInput()));
}


Dialog::~Dialog()
{

}
void Dialog::showInput()
{
    inputDlg = new InputDlg(this);
    inputDlg->show();

}

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!