【Qt5开发及实例】7、综合:修改用户资料

这是什么鬼,昨天我明明发上去了,要审核,今天一看,莫名其妙博客都不见了,草稿箱,回收站都没有!!!!!

CSDN你确定你没逗我???


哎重发一遍。

给个目标实现以下:



好的开始:

项目是:Example

基类是QDialog

类名是:Content


content.h

#ifndef CONTENT_H
#define CONTENT_H

#include <QStackedWidget>
#include <QPushButton>
#include "baseinfo.h"
#include "contact.h"
#include "detail.h"

class Content : public QFrame
{
  Q_OBJECT
public:
  Content(QWidget *parent = 0);
  QStackedWidget *stack;
  QPushButton *AmendBtn;
  QPushButton *CloseBtn;

  BaseInfo  *baseInfo;   //参考前面的章节
  Contact *contact;
  Detail *detail;


};

#endif // CONTENT_H

Content.cpp

#include "content.h"

Content::Content(QWidget *parent):QFrame(parent)
{
  stack = new QStackedWidget(this);
  stack->setFrameStyle(QFrame::Panel|QFrame::Raised); //设置框架的样式,这个是QFrame::Raised - 框架和内容看起来凸起,这个是画布的形状

  baseInfo = new BaseInfo();
  contact = new Contact();
  detail = new Detail();

  stack->addWidget(baseInfo);
  stack->addWidget(contact);
  stack->addWidget(detail);   //把这三个内容加入进去

  AmendBtn = new QPushButton(tr("修改"));
  CloseBtn = new QPushButton(tr("关闭"));
  QHBoxLayout *BtnLayout = new QHBoxLayout;
  BtnLayout->addStretch(1);   //就是一段弹簧一样,把按钮挤到右边去
  BtnLayout->addWidget(AmendBtn);
  BtnLayout->addWidget(CloseBtn);   //加入按钮

  QVBoxLayout *RightLayout = new QVBoxLayout(this);
  RightLayout->setMargin(10);   //设置控件之间的间隔
  RightLayout->setSpacing(6);
  RightLayout->addWidget(stack);
  RightLayout->addLayout(BtnLayout);

}

然后加一个头文件

BaseInfo.h  这个其实在前面发表的里面有,只是改了一下名字

http://blog.csdn.net/cutter_point/article/details/42084387


#include <QDialog>
#include <QLabel>
#include <QLineEdit>
#include <QComboBox>    //多选行
#include <QTextEdit>
#include <QGridLayout>    //网格布局
#include <QPushButton>

class BaseInfo : public QWidget
{
  Q_OBJECT

public:
  BaseInfo(QWidget *parent=0);
private:
  //左边的布局使用的控件
  QLabel *UserNameLabel;    //用户名的label
  QLabel *NameLabel;  //名字标签
  QLabel *SexLabel;   //性别
  QLabel *DepartmentLabel;   //用户文本
  QLabel *AgeLabel; //年龄
  QLabel *OtherLabel; //其他备注
  QLineEdit *UserNameLineEdit;  //输入用户名的控件
  QLineEdit *NameLineEdit;  //名字
  QComboBox *SexComboBox; //性别
  QTextEdit *DepartmentTextEdit;  //部门
  QLineEdit *AgeLineEdit; //年龄
  QGridLayout *LeftLayout;    //网格布局


  //右边布局
  QLabel *HeadLabel;    //右上角
  QLabel *HeadIconLabel;  //图片
  QPushButton *UpdateHeadBtn;   //更新按钮
  QHBoxLayout *TopRightLayout;  //水平布局


  QLabel *IntroductionLabel;    //介绍信息
  QTextEdit *IntroductionTextEdit;
  QVBoxLayout *RightLayout;   //垂直布局

};


baseinfo.cpp


#include "baseinfo.h"

BaseInfo::BaseInfo(QWidget *parent) : QWidget(parent)
{
  /******左侧******/
  UserNameLabel = new QLabel(tr("用户名:"));
  UserNameLineEdit = new QLineEdit;

  NameLabel = new QLabel(tr("姓名: "));
  NameLineEdit = new QLineEdit;

  SexLabel = new QLabel(tr("性别"));
  SexComboBox = new QComboBox;
  SexComboBox->addItem(tr("women"));
  SexComboBox->addItem(tr("man"));

  DepartmentLabel = new QLabel(tr("部门"));
  DepartmentTextEdit = new QTextEdit;     //文本输入的大框子

  AgeLabel = new QLabel(tr("部门"));
  AgeLineEdit = new QLineEdit;

  OtherLabel = new QLabel(tr("年龄"));
  OtherLabel->setFrameStyle(QFrame::Panel|QFrame::Sunken);

  LeftLayout = new QGridLayout();   //网格布局
  LeftLayout->addWidget(UserNameLabel, 0, 0);
  LeftLayout->addWidget(UserNameLineEdit, 0, 1);

  LeftLayout->addWidget(NameLabel, 1, 0);
  LeftLayout->addWidget(NameLineEdit, 1, 1);

  LeftLayout->addWidget(SexLabel, 2, 0);
  LeftLayout->addWidget(SexComboBox, 2, 1);

  LeftLayout->addWidget(DepartmentLabel, 3, 0);
  LeftLayout->addWidget(DepartmentTextEdit, 3, 1);

  LeftLayout->addWidget(AgeLabel, 4, 0);
  LeftLayout->addWidget(AgeLineEdit, 4, 1);

  LeftLayout->addWidget(OtherLabel, 5, 0, 1, 2);
  LeftLayout->setColumnStretch(0, 1);   //就是一个弹簧
  LeftLayout->setColumnStretch(1, 3);

  /**右侧**/
  HeadLabel = new QLabel(tr("头像: "));
  HeadIconLabel = new QLabel;
  QPixmap icon("312.png");
  HeadIconLabel->setPixmap(icon);   //设置图片
  HeadIconLabel->resize(icon.width(), icon.height()); //设置图片的加进去的宽和高
  UpdateHeadBtn = new QPushButton(tr("更新"));

  TopRightLayout = new QHBoxLayout();
  TopRightLayout->setSpacing(20);
  TopRightLayout->addWidget(HeadLabel);
  TopRightLayout->addWidget(HeadIconLabel);
  TopRightLayout->addWidget(UpdateHeadBtn);

  IntroductionLabel = new QLabel(tr("个人说明:"));    //右下角部分
  IntroductionTextEdit = new QTextEdit;

  RightLayout = new QVBoxLayout();
  RightLayout->setMargin(10);
  RightLayout->addLayout(TopRightLayout);
  RightLayout->addWidget(IntroductionLabel);
  RightLayout->addWidget(IntroductionTextEdit);

  /*******************************************/
  QGridLayout *mainLayout = new QGridLayout(this);
  mainLayout->setMargin(15);
  mainLayout->setSpacing(10);
  mainLayout->addLayout(LeftLayout, 0, 0);
  mainLayout->addLayout(RightLayout, 0, 1);
  mainLayout->setSizeConstraint(QLayout::SetFixedSize);


}

contact.h

//添加的头文件
#include <QLabel>
#include <QGridLayout>
#include <QLineEdit>
#include <QCheckBox>
class Contact : public QWidget
{
    Q_OBJECT
public:
    Contact(QWidget *parent=0);
private:
    QLabel *EmailLabel;
    QLineEdit *EmailLineEdit;
    QLabel *AddrLabel;
    QLineEdit *AddrLineEdit;
    QLabel *CodeLabel;
    QLineEdit *CodeLineEdit;
    QLabel *MoviTelLabel;
    QLineEdit *MoviTelLineEdit;
    QCheckBox *MoviTelCheckBook;
    QLabel *ProTelLabel;
    QLineEdit *ProTelLineEdit;
    QGridLayout *mainLayout;
};


contact.cpp

#include "contact.h"

Contact::Contact(QWidget *parent) : QWidget(parent)
{
  EmailLabel = new QLabel(tr("电子邮件:"));
  EmailLineEdit = new QLineEdit;

  AddrLabel = new QLabel(tr("联系地址:"));
  AddrLineEdit = new QLineEdit;

  CodeLabel = new QLabel(tr("邮政编码:"));
  CodeLineEdit = new QLineEdit;


  MoviTelLabel =new QLabel(tr("移动电话: "));
  MoviTelLineEdit =new QLineEdit;
  MoviTelCheckBook =new QCheckBox(tr("接收留言"));

  ProTelLabel =new QLabel(tr("办公电话: "));
  ProTelLineEdit =new QLineEdit;

  mainLayout =new QGridLayout(this);
  mainLayout->setMargin(15);
  mainLayout->setSpacing(10);<pre name="code" class="cpp">#ifndef DETAIL_H
#define DETAIL_H

//添加的头文件
#include <QLabel>
#include <QComboBox>
#include <QLineEdit>
#include <QTextEdit>
#include <QGridLayout>
class Detail : public QWidget
{
    Q_OBJECT
public:
    Detail(QWidget *parent=0);
private:
    QLabel *NationalLabel;
    QComboBox *NationalComboBox;
    QLabel *ProvinceLabel;
    QComboBox *ProvinceComboBox;
    QLabel *CityLabel;
    QLineEdit *CityLineEdit;
    QLabel *IntroductLabel;
    QTextEdit *IntroductTextEdit;
    QGridLayout *mainLayout;
};



#endif // DETAIL_H

mainLayout->addWidget(EmailLabel,0,0); mainLayout->addWidget(EmailLineEdit,0,1); mainLayout->addWidget(AddrLabel,1,0); mainLayout->addWidget(AddrLineEdit,1,1); mainLayout->addWidget(CodeLabel,2,0); mainLayout->addWidget(CodeLineEdit,2,1); mainLayout->addWidget(MoviTelLabel,3,0); mainLayout->addWidget(MoviTelLineEdit,3,1); mainLayout->addWidget(MoviTelCheckBook,3,2); mainLayout->addWidget(ProTelLabel,4,0); mainLayout->addWidget(ProTelLineEdit,4,1); mainLayout->setSizeConstraint(QLayout::SetFixedSize);}

 

detail.h

#ifndef DETAIL_H
#define DETAIL_H

//添加的头文件
#include <QLabel>
#include <QComboBox>
#include <QLineEdit>
#include <QTextEdit>
#include <QGridLayout>
class Detail : public QWidget
{
    Q_OBJECT
public:
    Detail(QWidget *parent=0);
private:
    QLabel *NationalLabel;
    QComboBox *NationalComboBox;
    QLabel *ProvinceLabel;
    QComboBox *ProvinceComboBox;
    QLabel *CityLabel;
    QLineEdit *CityLineEdit;
    QLabel *IntroductLabel;
    QTextEdit *IntroductTextEdit;
    QGridLayout *mainLayout;
};



#endif // DETAIL_H

detail.cpp


#ifndef DETAIL_H
#define DETAIL_H

//添加的头文件
#include <QLabel>
#include <QComboBox>
#include <QLineEdit>
#include <QTextEdit>
#include <QGridLayout>
class Detail : public QWidget
{
    Q_OBJECT
public:
    Detail(QWidget *parent=0);
private:
    QLabel *NationalLabel;
    QComboBox *NationalComboBox;
    QLabel *ProvinceLabel;
    QComboBox *ProvinceComboBox;
    QLabel *CityLabel;
    QLineEdit *CityLineEdit;
    QLabel *IntroductLabel;
    QTextEdit *IntroductTextEdit;
    QGridLayout *mainLayout;
};



#endif // DETAIL_H

主函数

main.cpp

/**
 * <p>我tm终于练成了!Hello World终于打印出来了! %>_<% 我先哭(激动)会~~~<p>
 * @version 1.0.1
 * @since JDK 1.6
 * @author jacksen
 *
 */

// 致终于来到这里的勇敢的人:
//    你是被上帝选中的人,英勇的、不辞劳苦的、不眠不休的来修改
// 我们这最棘手的代码的编程骑士。你,我们的救世主,人中龙凤,
// 我要对你说:永远不要放弃;永远不要对自己失望;永远不要逃走,辜负自己。
// 永远不要哭啼,永远不要说再见。永远不要说谎来伤害自己。

// 致终于来到这里的勇敢的人:
//    你是被上帝选中的人,英勇的、不辞劳苦的、不眠不休的来修改
// 我们这最棘手的代码的编程骑士。你,我们的救世主,人中龙凤,
// 我要对你说:永远不要放弃;永远不要对自己失望;永远不要逃走,辜负自己。
// 永远不要哭啼,永远不要说再见。永远不要说谎来伤害自己。


// 致终于来到这里的勇敢的人:
//    你是被上帝选中的人,英勇的、不辞劳苦的、不眠不休的来修改
// 我们这最棘手的代码的编程骑士。你,我们的救世主,人中龙凤,
// 我要对你说:永远不要放弃;永远不要对自己失望;永远不要逃走,辜负自己。
// 永远不要哭啼,永远不要说再见。永远不要说谎来伤害自己。


//頂頂頂頂頂頂頂頂頂 頂頂頂頂頂頂頂頂頂
//頂頂頂頂頂頂頂     頂頂
//   頂頂   頂頂頂頂頂頂頂頂頂頂頂
//   頂頂   頂頂頂頂頂頂頂頂頂頂頂
//   頂頂   頂頂       頂頂
//   頂頂   頂頂  頂頂頂  頂頂
//   頂頂   頂頂  頂頂頂  頂頂
//   頂頂   頂頂  頂頂頂  頂頂
//   頂頂   頂頂  頂頂頂  頂頂
//   頂頂       頂頂頂
//   頂頂      頂頂 頂頂 頂頂
// 頂頂頂頂   頂頂頂頂頂 頂頂頂頂頂
// 頂頂頂頂   頂頂頂頂   頂頂頂頂




/*code is far away from bug with the animal protecting
  *  ┏┓   ┏┓
  *┏┛┻━━━┛┻┓
  *┃       ┃
  *┃   ━   ┃
  *┃ ┳┛ ┗┳ ┃
  *┃       ┃
  *┃   ┻   ┃
  *┃       ┃
  *┗━┓   ┏━┛
  *  ┃   ┃神兽保佑
  *  ┃   ┃代码无BUG!
  *  ┃   ┗━━━┓
  *  ┃       ┣┓
  *  ┃       ┏┛
  *  ┗┓┓┏━┳┓┏┛
  *   ┃┫┫ ┃┫┫
  *   ┗┻┛ ┗┻┛
  *
  */




      /**
      *
      *----------Dragon be here!----------/

              ┏┓   ┏┓
            ┏┛┻━━━┛┻┓
            ┃       ┃
            ┃   ━   ┃
            ┃ ┳┛ ┗┳ ┃
            ┃       ┃
            ┃   ┻   ┃
            ┃       ┃
            ┗━┓   ┏━┛
                    ┃   ┃
                    ┃   ┃
                    ┃   ┗━━━┓
                    ┃       ┣┓
                    ┃       ┏┛
                    ┗┓┓┏━┳┓┏┛
                      ┃┫┫ ┃┫┫
                      ┗┻┛ ┗┻┛
          ━━━━━━神兽出没━━━━━━ */

      /**

                 ┏┓   ┏┓
               ┏┛┻━━━┛┻┓
               ┃       ┃
               ┃   ━   ┃
               ┃ >   < ┃
               ┃       ┃
               ┃       ... ⌒ ... ┃
               ┃       ┃
               ┗━┓   ┏━┛
                       ┃   ┃ Code is far away from bug with the animal protecting
                       ┃   ┃ 神兽保佑,代码无bug
                       ┃   ┃
                       ┃   ┃
                       ┃   ┃
                       ┃   ┃
                       ┃   ┗━━━┓
                       ┃       ┣┓
                       ┃       ┏┛
                       ┗┓┓┏━┳┓┏┛
                         ┃┫┫ ┃┫┫
                         ┗┻┛ ┗┻┛ */

      /**
      *        ┏┓   ┏┓+ +
      *       ┏┛┻━━━┛┻┓ + +
      *       ┃       ┃
      *       ┃   ━   ┃ ++ + + +
      *                            ┃ ████━████ ┃+
      *       ┃       ┃ +
      *       ┃   ┻   ┃
      *       ┃       ┃ + +
      *       ┗━┓   ┏━┛
      *         ┃   ┃
      *         ┃   ┃ + + + +
      *         ┃   ┃    Code is far away from bug with the animal protecting
      *         ┃   ┃ +     神兽保佑,代码无bug
      *         ┃   ┃
      *         ┃   ┃  +
      *         ┃    ┗━━━┓ + +
      *         ┃        ┣┓
      *         ┃        ┏┛
      *         ┗┓┓┏━┳┓┏┛ + + + +
      *          ┃┫┫ ┃┫┫
      *          ┗┻┛ ┗┻┛+ + + +
      */


//1只羊 == one sheep
//2只羊 == two sheeps
//3只羊 == three sheeps
//4只羊 == four sheeps
//5只羊 == five sheeps
//6只羊 == six sheeps
//7只羊 == seven sheeps
//8只羊 == eight sheeps
//9只羊 == nine sheeps
//10只羊 == ten sheeps
//11只羊 == eleven sheeps
//12只羊 == twelve sheeps
//13只羊 == thirteen sheeps
//14只羊 == fourteen sheeps
//15只羊 == fifteen sheeps
//16只羊 == sixteen sheeps
//17只羊 == seventeen sheeps
//18只羊 == eighteen sheeps
//19只羊 == nineteen sheeps
//20只羊 == twenty sheeps
//21只羊 == twenty one sheeps
//22只羊 == twenty two sheeps
//23只羊 == twenty three sheeps
//24只羊 == twenty four sheeps
//25只羊 == twenty five sheeps
//26只羊 == twenty six sheeps
//27只羊 == twenty seven sheeps
//28只羊 == twenty eight sheeps
//29只羊 == twenty nine sheeps
//30只羊 == thirty sheeps
//现在瞌睡了吧,好了,不要再改下面的代码了,睡觉咯~~


/**
 *      出生
 *       ||
 *       ||
 *      \  /
 *       \/
 *      青年
 * (年龄 = rand(20,25)))    《==============
 *       ||                                                                 ||
 *       ||                                                                 ||
 *       ||        祝福所有开发工作者                         ||
 *       ||            永远年轻                                       ||
 *       ||                                                                 ||
 *      \  /                                                                ||
 *       \/                                                                 ||
 *( 20 <= 年龄 <= 25)        ===============
 *       ||
 *       ||
 *      \  /
 *       \/
 *     等死状态
 */

#include "content.h"
#include <QApplication>
#include <QTextCodec>
#include <QSplitter>
#include <QListWidget>

int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  QFont font("AR PL KaitiM GB", 12);
  a.setFont(font);

  QSplitter *splitterMain = new QSplitter(Qt::Horizontal, 0);
  splitterMain->setOpaqueResize(true);

  QListWidget *list = new QListWidget;
  list->insertItem(0, QObject::tr("基本信息"));
  list->insertItem(1, QObject::tr("联系方式"));
  list->insertItem(2, QObject::tr("详细资料"));

  Content *content = new Content(splitterMain);

  QObject::connect(list, SIGNAL(currentRowChanged(int)), content->stack, SLOT(setCurrentIndex(int)));

  splitterMain->addWidget(list);
  splitterMain->setWindowTitle(QObject::tr("修改用户资料"));
  splitterMain->setMinimumSize(splitterMain->minimumSize());
  splitterMain->setMaximumSize(splitterMain->maximumSize());
  splitterMain->show();

  return a.exec();
}


有些图案错位了,调整一下就好,哈哈!!




我觉得我可以吧项目传上去!!!你们觉得呢!

下载链接不用积分哦:大笑,好吧,我刚刚上传了,但是坑爹的是我进不去我上传的资源那个界面,我又不知道是几个情况!!!!


下载地址:不知道为什么现在可以进去了


















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值