#include <QApplication>
#include <QDialog>
#include <QVBoxLayout>
#include <QLabel>
#include <QPushButton>
class CustomDialog : public QDialog {
Q_OBJECT
public:
CustomDialog(QWidget *parent = nullptr);
~CustomDialog(){}
};
CustomDialog::CustomDialog(QWidget *parent ): QDialog(parent) {
QVBoxLayout *layout = new QVBoxLayout(this);
QLabel *label = new QLabel("This is a custom dialog.", this);
layout->addWidget(label);
QPushButton *okButton = new QPushButton("OK", this);
layout->addWidget(okButton);
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
};
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
CustomDialog dialog;
dialog.exec(); // 显示自定义对话框
return app.exec();
}
#include "main.moc"
没有合适的资源?快使用搜索试试~ 我知道了~
Qt自定义对话框Demo
共2个文件
pro:1个
cpp:1个
0 下载量 3 浏览量
2023-10-14
09:30:46
上传
评论
收藏 1KB ZIP 举报
温馨提示
在Qt中,你可以创建自定义对话框(Custom Dialog)来满足特定需求,这允许你设计一个完全符合应用程序风格的对话框。通常,自定义对话框是通过创建一个继承自`QDialog`的自定义类,并在这个类中定义对话框的外观和行为。 以下是如何创建自定义对话框的基本步骤: 1. **创建一个自定义对话框类:** ```cpp #include <QDialog> class CustomDialog : public QDialog { Q_OBJECT public: CustomDialog(QWidget *parent = nullptr); // 添加自定义的成员函数和变量 }; ``` 2. **在自定义对话框类的实现中,设置对话框的外观和行为:** ```cpp #include "customdialog.h" #include <QVBoxLayout> #include <QLabel> #include <QPushButton> Cust
资源推荐
资源详情
资源评论
收起资源包目录
6_4.zip (2个子文件)
6_4
6_4.pro 1KB
main.cpp 824B
共 2 条
- 1
资源评论
三雷科技
- 粉丝: 3w+
- 资源: 100
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功