Qt 创建一个按钮,点击弹出和关闭对话框
#include "widget.h"
#include "ui_widget.h"
#include<QPushButton>
#include<QDialog>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
QDialog *w=new QDialog;
QPushButton *open=new QPushButton("open",this);
QPushButton *close=new QPushButton("close",this);
close->move(200,0);
connect(open,&QPushButton::clicked,w,[=](){
w->show();
});
connect(close,&QPushButton::clicked,w,[=](){
w->close();
});
}
Widget::~Widget()
{
delete ui;
}
笔记:在QDialog中,如果用exec()或setModal()会让父窗口点击不了。
效果图

本文介绍了如何在Qt中创建一个包含两个按钮的窗口,一个用于弹出对话框,另一个用于关闭。通过信号与槽连接实现对话框的显示和隐藏,同时说明了避免父窗口无法点击的问题。
5683

被折叠的 条评论
为什么被折叠?



