• 可伸缩对话框(含多重继承)


    extensionDlg.pro

    TEMPLATE = app
    TARGET =
    DEPENDPATH += .
    INCLUDEPATH += .
    
    # Input
    HEADERS += extensionDlg.h
    SOURCES += extensionDlg.cpp main.cpp

    extensionDlg.h

    #ifndef EXTENSIONDLG_H
    #define EXTENSIONDLG_H
    
    #include <QtGui>
    
    class ExtensionDlg : public QDialog
    {
        Q_OBJECT
    public:
    
        ExtensionDlg();
    
        void initBasicInfo();
        void initDetailInfo();
    
    public slots:
        void slotExtension();
    
    private:
        QWidget *baseWidget;
        QWidget *detailWidget;
    };
    
    #endif // EXTENSIONDLG_H

    extensionDlg.cpp

    #include "extensionDlg.h"
    
    ExtensionDlg::ExtensionDlg()
    {
        setWindowTitle(tr("Extension Dialog"));
    
        initBasicInfo();
        initDetailInfo();
    
    
        QVBoxLayout *layout = new QVBoxLayout;
        layout->addWidget(baseWidget);
        layout->addWidget(detailWidget);
        layout->setSizeConstraint(QLayout::SetFixedSize);
        layout->setSpacing(10);
        setLayout(layout);
    }
    
    void ExtensionDlg::initBasicInfo()
    {
        baseWidget = new QWidget;
    
        QLabel *nameLabel = new QLabel(tr("Name:"));
        QLineEdit *nameEdit = new QLineEdit;
        QLabel *sexLabel = new QLabel(tr("Sex:"));
        QComboBox *sexComboBox = new QComboBox;
        sexComboBox->addItem(tr("male"));
        sexComboBox->addItem(tr("female"));
    
        QPushButton *okButton = new QPushButton(tr("OK"));
        QPushButton *detailButton = new QPushButton(tr("Detail"));
        connect(detailButton,SIGNAL(clicked()),this,SLOT(slotExtension()));
    
        QDialogButtonBox *btnBox = new QDialogButtonBox(Qt::Vertical);
        btnBox->addButton(okButton,QDialogButtonBox::ActionRole);
        btnBox->addButton(detailButton,QDialogButtonBox::ActionRole);
    
        QGridLayout *grid = new QGridLayout;
        grid->addWidget(nameLabel,0,0);
        grid->addWidget(nameEdit,0,1);
        grid->addWidget(sexLabel,1,0);
        grid->addWidget(sexComboBox,1,1);
    
        QHBoxLayout *hbox = new QHBoxLayout;
        hbox->addLayout(grid);
        hbox->addStretch();
        hbox->addWidget(btnBox);
        baseWidget->setLayout(hbox);
    }
    
    void ExtensionDlg::initDetailInfo()
    {
        detailWidget = new QWidget;
    
        QLabel *label1 = new QLabel(tr("Age:"));
        QLineEdit *ageEdit = new QLineEdit;
        ageEdit->setText("30");
        QLabel *label2 = new QLabel(tr("Department:"));
        QComboBox *deptComboBox = new QComboBox;
        deptComboBox->addItem(tr("dept 1"));
        deptComboBox->addItem(tr("dept 2"));
        deptComboBox->addItem(tr("dept 3"));
        deptComboBox->addItem(tr("dept 4"));
        QLabel *label3 = new QLabel(tr("email:"));
        QLineEdit *edit = new QLineEdit;
    
        QGridLayout *grid = new QGridLayout;
        grid->addWidget(label1,0,0);
        grid->addWidget(ageEdit,0,1);
        grid->addWidget(label2,1,0);
        grid->addWidget(deptComboBox,1,1);
        grid->addWidget(label3,2,0);
        grid->addWidget(edit,2,1);
    
        detailWidget->setLayout(grid);
        detailWidget->hide();
    }
    
    void ExtensionDlg::slotExtension()
    {
        if (detailWidget->isHidden())
        {
            detailWidget->show();
        }
        else
        {
            detailWidget->hide();
        }
    }

    main.cpp

    #include <QApplication>
    #include "extensionDlg.h"
    
    int main(int argc, char * argv[])
    {
        QApplication app(argc,argv);
    
    
        ExtensionDlg exDlg;
        exDlg.show();
        return app.exec();
    }

    程序剖析文档下载地址:

    http://ishare.iask.sina.com.cn/f/35025724.html

  • 相关阅读:
    0101-ioc
    通过Android studio手动触发Android 上层GC(垃圾回收)的方法
    【Win10】BeyondCompare时提示"许可证密钥已被撤销"的解决办法
    Android Historian安装使用
    初探OpenCL之Mac OS上的hello world示例
    python画高斯分布图形
    深度学习优化算法总结
    《用Python玩转数据》项目—线性回归分析入门之波士顿房价预测(二)
    《用Python玩转数据》项目—线性回归分析入门之波士顿房价预测(一)
    (转)导数、偏导数、方向导数、梯度、梯度下降
  • 原文地址:https://www.cnblogs.com/elesos/p/2813731.html
Copyright © 2020-2023  润新知