Qt 实现可扩展对话框
来源:互联网 发布:win7 录屏软件 编辑:程序博客网 时间:2024/06/07 12:12
实现效果:
代码
1.extension.h文件#ifndef EXTENSION_H#define EXTENSION_H#include <QApplication>#include <QPushButton>#include <QDialog>#include <QGridLayout>#include <QWidget>#include <QHBoxLayout>#include <QLabel>#include <QLineEdit>#include <QComboBox>#include <QDialogButtonBox>#include <QGridLayout>#include <QDialog>class Extension : public QDialog{ Q_OBJECTpublic: Extension(QWidget *parent=0); void createBaseInfo(); void createDetailInfo();public slots: void slotExtension();private: QWidget *baseWidget; QWidget *detailWidget; };#endif // EXTENSION_H
2extension.cpp文件#include "extension.h"Extension::Extension(QWidget *parent):QDialog(parent){ setWindowTitle(tr("Extension Dialog")); createBaseInfo(); createDetailInfo(); QVBoxLayout *layout=new QVBoxLayout; layout->addWidget(baseWidget); layout->addWidget(detailWidget); layout->setSizeConstraint(QLayout::SetFixedSize); layout->setSpacing(10); setLayout(layout);}void Extension::createBaseInfo(){ 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("male"); sexComboBox->addItem("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 *gride = new QGridLayout; gride->addWidget(nameLabel,0,0); gride->addWidget(nameEdit,0,1); gride->addWidget(sexLabel,1,0); gride->addWidget(sexComboBox,1,1); QHBoxLayout *hbox = new QHBoxLayout; hbox->addLayout(gride); hbox->addStretch(); hbox->addWidget(btnBox); baseWidget->setLayout(hbox); }void Extension::createDetailInfo(){ 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 Extension::slotExtension(){ if(detailWidget->isHidden()) { detailWidget->show(); } else { detailWidget->hide(); }}
3.main.cpp文件#include<QApplication>#include"extension.h"int main(int argc,char *argv[]){ QApplication app(argc,argv); Extension exten; exten.show(); return app.exec();}
- Qt 实现可扩展对话框
- Qt 实现可扩展对话框
- Qt:可扩展对话框的实现
- Qt 可扩展对话框创建--实验
- qt学习笔记可扩展对话框
- QT学习 之 对话框 (一) 可扩展对话框
- 用QtCreator实现可扩展对话框实验
- python3+PyQt5+Qt Designer实现扩展对话框
- python3+PyQt5+Qt Designer实现扩展对话框
- 可扩展的对话框
- 可扩展对话框
- 可扩展的对话框
- qt-扩展对话框
- QT 类及其实现效果(2)--QPalette和扩展对话框
- qt学习之扩展对话框
- QT对话框实现
- Qt标准对话框实现
- MFC对话框扩展区域显示(可伸缩对话框区域)
- Android学习笔记(四十):Preference的使用
- java web高级第一章 解析xml
- iOS 实现简单的移动UIView代码实例
- cairo 教程5
- Android学习笔记(四一):SQLite的使用
- Qt 实现可扩展对话框
- Jquery Tools从零开始
- Android学习笔记(四二):SQLite、ListView、ContextMenu
- 百度竞价排名的基本知识
- jrockit之-XXexitOnOutOfMemory参数
- Android学习笔记(四三):文件访问
- php服务端与android客户端socket通信
- 【python】刷票机
- 常用Android命令行工具,包括真机上的操作