Important: Please read the Qt Code of Conduct -

How to remove minimize button from QMessageBox

  • Hi,

    I am using Qt Creator in RaspberryPi3(Linux) , When I create a message box Minimize Button is displayed .

    How to remove Minimize button ?
    As another method,
    Is there a way to ignore it even if I press the minimize button?

    The development environment is as follows.

    RaspberryPi3 , Raspbian GNU/Linux 9.1 (stretch)
    Qt Creator 4.2.0、Qt 5.7.1 (GCC 6.2.1 20161124, 32 bit)

  • Lifetime Qt Champion

    @Kucchan See and Qt::WindowMinimizeButtonHint

  • Dear jsulm
    Thank you for your comment.
    But I can not solve the problem.

    I tried the following contents, but I could hide the minimize button in Windows OS, but in RaspberryPi 3 (Linux) I could not hide the minimize button.

    How can I hide the minimize button on RaspberryPi 3?

  • @Kucchan
    You may not be able to. It depends on whether your OS/desktop allows this, Qt is using platform's native windows, Windows does, there is no guarantee that Pi/Ubuntu/GNOME or whatever you are using supports removing just the minimize button.

    For example, from the Qt docs:

    In Linux with KDE this code make a window without an close and minimize and maximize buttons in title bar.

    setWindowFlags( Qt::Dialog | Qt::WindowTitleHint );

  • QMessageBox box.
    box.setWindowFlags(box.windowFlags() & (~Qt::WindowMinimizeButtonHint));

    Should do the trick, but as @JNBarchan mentioned earlier it's platform dependent.

  • @dream_captain
    Since he says:

    I tried the following contents, but I could hide the minimize button in Windows OS, but in RaspberryPi 3 (Linux) I could not hide the minimize button.

    I presume that indicates he has the right code, it works under Windows but not under Linux....

  • Thank you everyone.

    I tried '~ Qt :: WindowMinimizeButtonHint' but it was useless.
    It seems impossible to remove Minimize button.
    So,Please tell me how to not minimize the window by clicking the minimize button.

  • Lifetime Qt Champion


    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.

    QT += core gui
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    TARGET = MsgBox
    TEMPLATE = app
    SOURCES += main.cpp
    HEADERS += mainwindow.h
    FORMS += mainwindow.ui


    #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;
    return a.exec();



    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QMessageBox>

    MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)

    delete ui;

    void MainWindow::on_pushButton_clicked()
    QMessageBox msgBox(this);
    msgBox.setWindowFlags(Qt::Window | Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint);


    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>

    namespace Ui {
    class MainWindow;

    class MainWindow : public QMainWindow

    explicit MainWindow(QWidget *parent = 0);

    private slots:
    void on_pushButton_clicked();

    Ui::MainWindow *ui;

    #endif // MAINWINDOW_H


    Only QpushButton is placed in MainWindow.

  • @Kucchan
    I was able to add and then remove minimize button from QMessageBox on my Linux Mint by setting Qt::Window flag first and then removing Qt::WindowMinimizeButtonHint

    QMessageBox msgBox;
    msgBox.setWindowFlags(Qt::Window );     // add minimize button
    msgBox.setWindowFlags(msgBox.windowFlags()&(~Qt::WindowMinimizeButtonHint)); // remove minimize button

    Give it a try. Set Qt::Window and then remove Qt::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?

  • @dream_captain

    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.

  • Lifetime Qt Champion

    @Kucchan I think this is not a problem with Qt but with window manager used. As far as I know Raspbian uses its own (Pixel?).

  • Is there no way?
    Do I need to give up?

  • @Kucchan
    You can try an ugly workaround: derive from QDialog and play around Qt::FramelessWindowHint to hide top buttons completely. Then add QPushButton on form and create a connection connect(ui->closeButton, &QPushButton::clicked, this, &QDialog::accept);' to imitate QMessageBox behavior.

  • @dream_captain

    Thank you for your comment.
    I will make a message box by QDialog.

  • @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.

Log in to reply