C++ Qt編程實踐——收貨人資訊清單

來源:互聯網
上載者:User

標籤:private   address   include   public   parent   

  收貨人資訊清單(改進中):

dialog.h檔案:

#ifndef DIALOG_H#define DIALOG_H#include <QDialog>#include <QLineEdit>#include <QLabel>#include <QPushButton>#include <QComboBox>class Dialog : public QDialog{    Q_OBJECTpublic:    Dialog(QWidget *parent = 0);    ~Dialog();signals:private slots:    void clearEditLine();    void saveClicked();private:    QLabel *name;    QLabel *area;    QLabel *address;    QLabel *phone;    QLabel *huo;    QLabel *tel;    QLabel *email;    QLabel *addressAliase;    QLabel *note;    QLineEdit *editName;    QComboBox *cobProvince;    QComboBox *cobCity;    QComboBox *cobArea;    QLineEdit *editAddress;    QLineEdit *editPhone;    QLineEdit *editTel;    QLineEdit *editEmail;    QLineEdit *editAddressAliase;    QPushButton *save;};#endif // DIALOG_H

dialog.cpp檔案:

#include "dialog.h"#include <QtGui>#include <QLayout>Dialog::Dialog(QWidget *parent)    : QDialog(parent){    name = new QLabel(tr("收貨人:"));    editName = new QLineEdit;    name->setBuddy(editName);    area = new QLabel(tr("所在地區:"));    cobProvince = new QComboBox();    cobProvince->addItem(tr("請選擇"));    cobProvince->addItem(tr("陝西"));    cobCity = new QComboBox();    cobCity->addItem(tr("請選擇"));    cobCity->addItem(tr("西安市"));    cobArea = new QComboBox();    cobArea->addItem(tr("請選擇"));    cobArea->addItem(tr("未央區"));    cobArea->addItem(tr("長安區"));    cobArea->addItem(tr("碑林區"));    cobArea->addItem(tr("新城區"));    cobArea->addItem(tr("高新區"));    cobArea->addItem(tr("蓮湖區"));    cobArea->addItem(tr("雁塔區"));    cobArea->addItem(tr("臨潼區"));    address = new QLabel(tr("詳細地址:"));    editAddress = new QLineEdit;    address->setBuddy(editAddress);    phone = new QLabel(tr("手機號碼:"));    editPhone = new QLineEdit;    phone->setBuddy(editPhone);    huo = new QLabel(tr("或"));    tel = new QLabel(tr("固定電話:"));    editTel = new QLineEdit;    tel->setBuddy(editTel);    email = new QLabel(tr("郵箱:"));    editEmail = new QLineEdit;    email->setBuddy(editEmail);    addressAliase = new QLabel(tr("地址別名:"));    editAddressAliase = new QLineEdit;    addressAliase->setBuddy(editAddressAliase);    note = new QLabel(tr("設定一個易記的名稱,如:“送到家裡”、“送到公司”"));    save = new QPushButton(tr("儲存收貨地址"));    connect(save, SIGNAL(clicked()), this, SLOT(saveClicked()));    QHBoxLayout *areaLayout = new QHBoxLayout;    areaLayout->addWidget(cobProvince);    areaLayout->addWidget(cobCity);    areaLayout->addWidget(cobArea);    QVBoxLayout *leftPhone = new QVBoxLayout;    leftPhone->addWidget(phone);    leftPhone->addWidget(editPhone);    //leftPhone->addStretch();    QVBoxLayout *rightTel = new QVBoxLayout;    rightTel->addWidget(tel);    rightTel->addWidget(editTel);    //rightTel->addStretch();    QHBoxLayout *numLayout = new QHBoxLayout;    numLayout->addLayout(leftPhone);    numLayout->addWidget(huo);    numLayout->addLayout(rightTel);    //numLayout->addStretch();    QHBoxLayout *aliaseLayout = new QHBoxLayout;    aliaseLayout->addWidget(editAddressAliase);    aliaseLayout->addWidget(note);    //aliaseLayout->addStretch();    QVBoxLayout *leftMainLayout = new QVBoxLayout;    leftMainLayout->addWidget(name);    leftMainLayout->addWidget(editName, 10);    leftMainLayout->addWidget(area);    //    leftMainLayout->addLayout(areaLayout);    leftMainLayout->addWidget(address);    leftMainLayout->addWidget(editAddress);    leftMainLayout->addLayout(numLayout);    leftMainLayout->addWidget(email);    leftMainLayout->addWidget(editEmail);    leftMainLayout->addWidget(addressAliase);    leftMainLayout->addLayout(aliaseLayout);    leftMainLayout->addWidget(save, 20);    //leftMainLayout->addStretch();    QVBoxLayout *rightMainLayout = new QVBoxLayout;    QHBoxLayout *mainLayout = new QHBoxLayout;    mainLayout->addLayout(leftMainLayout);    mainLayout->addLayout(rightMainLayout, 10);    setLayout(mainLayout);    setWindowTitle(tr("添加收貨地址"));    setFixedHeight(sizeHint().height());    setFixedWidth(sizeHint().width());}Dialog::~Dialog(){}void Dialog::clearEditLine(){    editName->setText("");    //cobProvince->setItemText(1);    editAddress->setText("");    editPhone->setText("");    editTel->setText("");    editEmail->setText("");    editAddressAliase->setText("");}void Dialog::saveClicked(){    QDialog *ShowDialog = new QDialog;    QString textName = editName->text();    QString textProvince = cobProvince->currentText();    QString textCity = cobCity->currentText();    QString textArea = cobArea->currentText();    QString textAddress = editAddress->text();    QString textPhone = editPhone->text();    QString textTel = editTel->text();    QString textEmail = editEmail->text();    QString textAddressAliase = editAddressAliase->text();    QLabel *showName = new QLabel(name->text() + textName);    QLabel *showArea = new QLabel(area->text() + textProvince + textCity + textArea);    QLabel *showAddress = new QLabel(address->text() + textAddress);    QLabel *showPhone = new QLabel(phone->text() + textPhone);    QLabel *showTel = new QLabel(tel->text() + textTel);    QLabel *showEmail = new QLabel(email->text() + textEmail);    QLabel *showAddressAliase = new QLabel(addressAliase->text() + textAddressAliase);    QPushButton *editText = new QPushButton(tr("編輯"));    QPushButton *deleteText = new QPushButton(tr("刪除"));    ShowDialog->connect(editText, SIGNAL(clicked()), ShowDialog, SLOT(close()));    ShowDialog->connect(deleteText, SIGNAL(clicked()), ShowDialog, SLOT(close()));    ShowDialog->connect(deleteText, SIGNAL(clicked()), this, SLOT(clearEditLine()));    QHBoxLayout *buttonLayout = new QHBoxLayout;    buttonLayout->addWidget(editText);    buttonLayout->addWidget(deleteText);    QVBoxLayout *mainLayout = new QVBoxLayout;    mainLayout->addLayout(buttonLayout);    mainLayout->addWidget(showName);    mainLayout->addWidget(showArea);    mainLayout->addWidget(showAddress);    mainLayout->addWidget(showPhone);    mainLayout->addWidget(showTel);    mainLayout->addWidget(showEmail);    mainLayout->addWidget(showAddressAliase);    ShowDialog->setLayout(mainLayout);    ShowDialog->setWindowTitle(textName + textArea);    ShowDialog->exec();}

main.cpp檔案:

#include "dialog.h"#include <QApplication>int main(int argc, char *argv[]){    QApplication a(argc, argv);    Dialog w;    w.show();    return a.exec();}

運行:

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/5B/E7/wKiom1UVSsSDGqttAAEjeeFa5NE608.jpg" title="收貨人清單" alt="wKiom1UVSsSDGqttAAEjeeFa5NE608.jpg" />

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/5B/E1/wKioL1UVTGugdvMlAACRAg3AWVY611.jpg" title="收貨人清單2" alt="wKioL1UVTGugdvMlAACRAg3AWVY611.jpg" />


本文出自 “V臉” 部落格,請務必保留此出處http://xuzhen1024.blog.51cto.com/8881317/1625810

C++ Qt編程實踐——收貨人資訊清單

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.