• Qt之对话框设计——可扩展对话框


    彩虹利用setSizeConstraint(QLayout::SetFixedSize)方法使对话框尺寸保持相对固定(有控件决定),不能经过拖动改变大小。


    image

    image

    extension.h

    #ifndef EXTENSION_H
    #define EXTENSION_H
    
    #include <QtGui/QDialog>
    #include <QWidget>
    
    class Extension : public QDialog
    {
    	Q_OBJECT
    
    public:
    	Extension(QWidget *parent = 0, Qt::WFlags flags = 0);
    	~Extension();
    
    	void createBaseInfo();
    	void createDetaiInfo();
    
    private:
    	QWidget *baseWidget;
    	QWidget *detaiWidget;
    
    	public slots:
    		void sl_Extension();
    	
    };
    
    #endif // EXTENSION_H
    

    extension.cpp

    #include "extension.h"
    #include <QVBoxLayout>
    #include <QGridLayout>
    #include <QLabel>
    #include <QLineEdit>
    #include <QComboBox>
    #include <QPushButton>
    
    Extension::Extension(QWidget *parent, Qt::WFlags flags)
    	: QDialog(parent, flags)
    {
    	setWindowTitle(tr("Extension Dialog"));
    
    	createBaseInfo();
    	createDetaiInfo();
    
    	QVBoxLayout *mainLayout = new QVBoxLayout(this);
    	mainLayout->addWidget(baseWidget);
    	mainLayout->addWidget(detaiWidget);
    	mainLayout->setSpacing(10);
    	mainLayout->setSizeConstraint(QLayout::SetFixedSize);
    }
    
    Extension::~Extension()
    {
    
    }
    
    void Extension::createBaseInfo()
    {
    	baseWidget = new QWidget;
    
    	QLabel *labName = new QLabel(tr("Name:"));
    	QLabel *labSex = new QLabel(tr("Sex:"));
    	QLineEdit *edtName = new QLineEdit;
    	QComboBox *cbbSex = new QComboBox;
    	cbbSex->insertItem(0,tr("male"));
    	cbbSex->insertItem(1,tr("female"));
    	QPushButton *btnOk = new QPushButton(tr("Ok"));
    	QPushButton *btnDetai = new QPushButton(tr("Detai"));
    	connect(btnDetai,SIGNAL(clicked()),this,SLOT(sl_Extension()));
    
    	QGridLayout *baseLayout = new QGridLayout(baseWidget);
    	baseLayout->addWidget(labName,0,0);
    	baseLayout->addWidget(edtName,0,1);
    	baseLayout->addWidget(btnOk,0,2);
    	baseLayout->addWidget(labSex,1,0);
    	baseLayout->addWidget(cbbSex,1,1);
    	baseLayout->addWidget(btnDetai,1,2);
    	baseLayout->setMargin(10);
    	baseLayout->setSpacing(10);
    
    }
    
    void Extension::createDetaiInfo()
    {
    	detaiWidget = new QWidget;
    
    	QLabel *labAge = new QLabel(tr("Age:"));
    	QLabel *labDepartment = new QLabel(tr("Department:"));
    	QLabel *labEmail = new QLabel(tr("Email:"));
    	QLineEdit *edtAge = new QLineEdit;
    	QComboBox *cbbDepartment = new QComboBox;
    	cbbDepartment->insertItem(0,tr("Department 1"));
    	cbbDepartment->insertItem(1,tr("Department 2"));
    	cbbDepartment->insertItem(2,tr("Department 3"));
    	QLineEdit *edtEmail = new QLineEdit;
    
    	QGridLayout *detaiLayout = new QGridLayout(detaiWidget);
    	detaiLayout->addWidget(labAge,0,0);
    	detaiLayout->addWidget(labDepartment,1,0);
    	detaiLayout->addWidget(labEmail,2,0);
    	detaiLayout->addWidget(edtAge,0,1);
    	detaiLayout->addWidget(cbbDepartment,1,1);
    	detaiLayout->addWidget(edtEmail,2,1);
    	detaiLayout->setMargin(10);
    	detaiLayout->setSpacing(10);
    
    	detaiWidget->hide();
    }
    
    void Extension::sl_Extension()
    {
    	if (detaiWidget->isHidden())
    	{
    		detaiWidget->show();
    	}
    	else
    	{
    		detaiWidget->hide();
    	}
    }
    

  • 相关阅读:
    Pikachu-RCE【远程代码、命令执行漏洞】
    Pikachu-SQL注入
    Pikachu-CSRF【跨站请求伪造】
    DWVA-xss【跨脚本漏洞】三类
    git 本地修改未提交时切换分支
    windows密码修改后同步修改git认证密码,HTTP Basic: Access denied and fatal Authentication
    git远程仓库回退
    git版本回退
    idea强制更新Maven依赖包
    IDEA多Module项目
  • 原文地址:https://www.cnblogs.com/hanzhaoxin/p/2775282.html
Copyright © 2020-2023  润新知