QT禁用窗口关闭
按钮的实现方法,直接在窗体类构造函数的内部写入setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint)
即可实现,案例如下:
#include "form.h"
#include "ui_form.h"Form::Form(QWidget *parent) :QWidget(parent),ui(new Ui::Form)
{ui->setupUi(this);setWindowFlags(Qt::CustomizeWindowHint |Qt::WindowMinimizeButtonHint |Qt::WindowMaximizeButtonHint);
}Form::~Form()
{delete ui;
}
前后对比效果如下:
第二种方法是重写closeEvent事件函数,如下图所示:
参考链接:
- http://www.manongjc.com/detail/56-rkpharsexsmoexb.html
- https://qa.1r1g.com/sf/ask/2209970031/
- https://blog.csdn.net/iqw17532/article/details/128280221