How to remove minimize button from QMessageBox
-
Hi,
Can you show the code you are currently using for your message box ?
-
Dear SGaist
It is the code that challenged to remove minimize button of MainWindow and QMessageBox.
MsgBox.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = MsgBox
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.uimain.cpp
#include "mainwindow.h"
#include <QApplication>int main(int argc, char *argv[])
{
Qt::WindowFlags flags;QApplication a(argc, argv); MainWindow w; flags = w.windowFlags(); flags = flags & ~Qt::WindowMinimizeButtonHint; w.setWindowFlags(flags); w.show(); return a.exec();}
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::on_pushButton_clicked()
{
QMessageBox msgBox(this);
msgBox.setText(tr("MessageText"));
msgBox.setWindowTitle(tr("Title"));
msgBox.setIcon(QMessageBox::Critical);
msgBox.setWindowFlags(Qt::Window | Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint);
msgBox.exec();
}mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();private slots:
void on_pushButton_clicked();private:
Ui::MainWindow *ui;
};#endif // MAINWINDOW_H
mainwindow.ui
Only QpushButton is placed in MainWindow.
-
Dear SGaist
It is the code that challenged to remove minimize button of MainWindow and QMessageBox.
MsgBox.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = MsgBox
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.uimain.cpp
#include "mainwindow.h"
#include <QApplication>int main(int argc, char *argv[])
{
Qt::WindowFlags flags;QApplication a(argc, argv); MainWindow w; flags = w.windowFlags(); flags = flags & ~Qt::WindowMinimizeButtonHint; w.setWindowFlags(flags); w.show(); return a.exec();}
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::on_pushButton_clicked()
{
QMessageBox msgBox(this);
msgBox.setText(tr("MessageText"));
msgBox.setWindowTitle(tr("Title"));
msgBox.setIcon(QMessageBox::Critical);
msgBox.setWindowFlags(Qt::Window | Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint);
msgBox.exec();
}mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();private slots:
void on_pushButton_clicked();private:
Ui::MainWindow *ui;
};#endif // MAINWINDOW_H
mainwindow.ui
Only QpushButton is placed in MainWindow.
@Kucchan
I was able to add and then remove minimize button fromQMessageBoxon my Linux Mint by settingQt::Windowflag first and then removingQt::WindowMinimizeButtonHintQMessageBox msgBox; msgBox.setText("MessageText"); msgBox.setWindowTitle("Title"); msgBox.setWindowFlags(Qt::Window ); // add minimize button msgBox.setWindowFlags(msgBox.windowFlags()&(~Qt::WindowMinimizeButtonHint)); // remove minimize button msgBox.setIcon(QMessageBox::Critical); msgBox.exec();Give it a try. Set
Qt::Windowand then removeQt::WindowMinimizeButtonHint -
-
Dear dream_captain
Thank you for your comment.
But It was useless in the RaspberryPi3.If the minimize button can be remove, without
' ~Qt::WindowMinimizeButtonHint:WindowMinimizeButtonHint '.
(WindowsOS and Ubuntu)RaspberryPi3 seems to be unique.
@Kucchan
I don't think that you can inherit from QMessageBox and just ignore minimize event, since it's controlled by window manager.Does QDialog come with minimize button by default on your rasp?
-
@Kucchan
I don't think that you can inherit from QMessageBox and just ignore minimize event, since it's controlled by window manager.Does QDialog come with minimize button by default on your rasp?
Does QDialog come with minimize button by default on your rasp?
I tried QDialog on RaspberryPi3 and the minimize button was displayed.
(Not change WindowFlags.WindowFlags is default value)QDialog can’t remove minimize button by changing WindowFlags.
-
Does QDialog come with minimize button by default on your rasp?
I tried QDialog on RaspberryPi3 and the minimize button was displayed.
(Not change WindowFlags.WindowFlags is default value)QDialog can’t remove minimize button by changing WindowFlags.
-
@Kucchan
You can try an ugly workaround: derive fromQDialogand play aroundQt::FramelessWindowHintto hide top buttons completely. Then addQPushButtonon form and create a connectionconnect(ui->closeButton, &QPushButton::clicked, this, &QDialog::accept);'to imitateQMessageBoxbehavior. -
@Kucchan
You can try an ugly workaround: derive fromQDialogand play aroundQt::FramelessWindowHintto hide top buttons completely. Then addQPushButtonon form and create a connectionconnect(ui->closeButton, &QPushButton::clicked, this, &QDialog::accept);'to imitateQMessageBoxbehavior.Thank you for your comment.
I will make a message box by QDialog. -
Dear SGaist
It is the code that challenged to remove minimize button of MainWindow and QMessageBox.
MsgBox.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = MsgBox
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.uimain.cpp
#include "mainwindow.h"
#include <QApplication>int main(int argc, char *argv[])
{
Qt::WindowFlags flags;QApplication a(argc, argv); MainWindow w; flags = w.windowFlags(); flags = flags & ~Qt::WindowMinimizeButtonHint; w.setWindowFlags(flags); w.show(); return a.exec();}
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::on_pushButton_clicked()
{
QMessageBox msgBox(this);
msgBox.setText(tr("MessageText"));
msgBox.setWindowTitle(tr("Title"));
msgBox.setIcon(QMessageBox::Critical);
msgBox.setWindowFlags(Qt::Window | Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint);
msgBox.exec();
}mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();private slots:
void on_pushButton_clicked();private:
Ui::MainWindow *ui;
};#endif // MAINWINDOW_H
mainwindow.ui
Only QpushButton is placed in MainWindow.
@Kucchan Too late with the answer, but this works for me on a RPi3 with Raspbian:
msgBox.setWindowFlags( ( Qt::Window | Qt::CustomizeWindowHint ) &~ ( Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint ) );someone else could be looking for the same answer as I did.