当前位置: 首页 > news >正文

qt-16可扩展对话框--隐藏和展现

可扩展对话框

  • 知识点
  • extension.h
  • extension.cpp
  • main.cpp
  • 运行图
    • 初始化隐藏
    • 展现--点击--详细按钮

知识点

MainLayout->setSizeConstraint(QLayout::SetFixedSize);//固定窗口大小

extension.h

#ifndef EXTENSION_H
#define EXTENSION_H#include <QDialog>class Extension : public QDialog
{Q_OBJECTpublic:Extension(QWidget *parent = nullptr);~Extension();
private slots:void ShowDetailInfo();
private:void CreateBaseInfo();void CreateDetailInfo();QWidget* BaseWidget;QWidget* DetailWidget;
};
#endif // EXTENSION_H

extension.cpp

#include "extension.h"
#include <QVBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QComboBox>
#include <QPushButton>
#include <QDialogButtonBox>
#include <QHBoxLayout>Extension::Extension(QWidget *parent): QDialog(parent)
{setWindowTitle(tr("Extension Dialog"));CreateBaseInfo();CreateDetailInfo();QVBoxLayout* MainLayout = new QVBoxLayout(this);MainLayout->addWidget(BaseWidget);MainLayout->addWidget(DetailWidget);//MainLayout->setSizeConstraint(QLayout::SetFixedSize);//固定窗口大小MainLayout->setSpacing(10);
}Extension::~Extension() {}void Extension::ShowDetailInfo()
{if(DetailWidget->isHidden()){DetailWidget->show();return;}DetailWidget->hide();}void Extension::CreateBaseInfo()
{BaseWidget = new QWidget;QLabel* NameLabel = new QLabel(tr("姓名:"));QLineEdit* NameLineEdit = new QLineEdit;QLabel* SexLabel = new QLabel("性别:");QComboBox* SexComboBox = new QComboBox;SexComboBox->insertItem(0,tr("男"));SexComboBox->insertItem(1,tr("女"));QGridLayout* LeftLayout = new QGridLayout;LeftLayout->addWidget(NameLabel,0,0);LeftLayout->addWidget(NameLineEdit,0,1);LeftLayout->addWidget(SexLabel,1,0);LeftLayout->addWidget(SexComboBox,1,1);QPushButton* OkBtn = new QPushButton(tr("确定"));QPushButton* DetailBtn = new QPushButton(tr("详细"));QDialogButtonBox* BtnBox = new QDialogButtonBox(Qt::Vertical);BtnBox->addButton(OkBtn,QDialogButtonBox::ActionRole);BtnBox->addButton(DetailBtn,QDialogButtonBox::ActionRole);//主布局QHBoxLayout* MainLayout = new QHBoxLayout(BaseWidget);MainLayout->addLayout(LeftLayout);MainLayout->addWidget(BtnBox);//事件connect(DetailBtn,SIGNAL(clicked()),this,SLOT(ShowDetailInfo()));
}void Extension::CreateDetailInfo()
{DetailWidget = new QWidget;QLabel* AgeLabel = new QLabel(tr("年龄"));QLineEdit* AgeLineEdit = new QLineEdit(tr("30"));QLabel* DepartmentLabel = new QLabel(tr("部门:"));QComboBox* DepartmentComboBox = new QComboBox;DepartmentComboBox->addItem(tr("部门1"));DepartmentComboBox->addItem(tr("部门2"));DepartmentComboBox->addItem(tr("部门3"));DepartmentComboBox->addItem(tr("部门4"));QLabel* EmailLabel = new QLabel(tr("Email:"));QLineEdit* EmailEdit = new QLineEdit;//布局QGridLayout* MainLayout = new QGridLayout(DetailWidget);MainLayout->addWidget(AgeLabel,0,0);MainLayout->addWidget(AgeLineEdit,0,1);MainLayout->addWidget(DepartmentLabel,1,0);MainLayout->addWidget(DepartmentComboBox,1,1);MainLayout->addWidget(EmailLabel,2,0);MainLayout->addWidget(EmailEdit,2,1);DetailWidget->hide();}

main.cpp

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

运行图

初始化隐藏

在这里插入图片描述

展现–点击–详细按钮

在这里插入图片描述


http://www.mrgr.cn/news/4470.html

相关文章:

  • IaaS,PaaS,aPaaS,SaaS,FaaS,如何区分?
  • OpenCV与AI深度学习 | 使用OpenCV图像修复技术去除眩光
  • python 可迭代,迭代器,生成器,装饰器
  • 解析“吃豆人”小游戏,附赠免费完整代码
  • Linux别名与用户管理体系
  • 紫光同芯推出全球首颗开放式架构安全芯片E450R
  • 字符函数和字符串函数(三)
  • Matplotlib基础入门--数据分析三大件完结
  • 【Nginx】实现 FastCGI
  • 区分有向图和无向图:连通分量
  • [Meachines] [Medium] solidstate Apache JAMES RCE+POP3邮件泄露+定时任务权限提升
  • 在亚马逊云科技上对Stable Diffusion模型提示词、输出图像内容进行安全审核
  • 小程序如何引入自定义组件
  • Linux 开机自动挂载共享文件设置
  • WPS回应“崩了”:提供15天会员补偿,另有新羊毛,你还不来薅?
  • Redis的缓存穿透、击穿、雪崩
  • Android T about screen rotation(二)
  • ArcGIS基础实战丨地图制作、数据制备、矢量空间分析、栅格空间分析、空间插值、DEM数据、
  • SpringBoot如何做自动配置
  • Redis7基础篇(八)