Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to remove minimize button from QMessageBox
Forum Updated to NodeBB v4.3 + New Features

How to remove minimize button from QMessageBox

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
18 Posts 6 Posters 9.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kucchan
    wrote on 24 Nov 2017, 09:46 last edited by
    #1

    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)

    J 1 Reply Last reply 24 Nov 2017, 10:18
    0
    • K Kucchan
      24 Nov 2017, 09:46

      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)

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 24 Nov 2017, 10:18 last edited by
      #2

      @Kucchan See http://doc.qt.io/qt-5/qwidget.html#windowFlags-prop and Qt::WindowMinimizeButtonHint

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • K Offline
        K Offline
        Kucchan
        wrote on 27 Nov 2017, 04:19 last edited by
        #3

        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.
        http://doc.qt.io/qt-5/qtwidgets-widgets-windowflags-example.html

        How can I hide the minimize button on RaspberryPi 3?

        J 1 Reply Last reply 27 Nov 2017, 08:08
        0
        • K Kucchan
          27 Nov 2017, 04:19

          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.
          http://doc.qt.io/qt-5/qtwidgets-widgets-windowflags-example.html

          How can I hide the minimize button on RaspberryPi 3?

          J Offline
          J Offline
          JonB
          wrote on 27 Nov 2017, 08:08 last edited by
          #4

          @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 );

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dream_captain
            wrote on 27 Nov 2017, 09:26 last edited by
            #5
            QMessageBox box.
            box.setText("randomText");
            box.setWindowFlags(box.windowFlags() & (~Qt::WindowMinimizeButtonHint));
            

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

            J 1 Reply Last reply 27 Nov 2017, 09:42
            0
            • D dream_captain
              27 Nov 2017, 09:26
              QMessageBox box.
              box.setText("randomText");
              box.setWindowFlags(box.windowFlags() & (~Qt::WindowMinimizeButtonHint));
              

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

              J Offline
              J Offline
              JonB
              wrote on 27 Nov 2017, 09:42 last edited by
              #6

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

              1 Reply Last reply
              0
              • K Offline
                K Offline
                Kucchan
                wrote on 27 Nov 2017, 10:03 last edited by
                #7

                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.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 27 Nov 2017, 10:16 last edited by
                  #8

                  Hi,

                  Can you show the code you are currently using for your message box ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    Kucchan
                    wrote on 28 Nov 2017, 01:10 last edited by
                    #9

                    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.ui

                    main.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_OBJECT

                    public:
                    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.

                    D U 2 Replies Last reply 28 Nov 2017, 04:46
                    0
                    • K Kucchan
                      28 Nov 2017, 01:10

                      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.ui

                      main.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_OBJECT

                      public:
                      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.

                      D Offline
                      D Offline
                      dream_captain
                      wrote on 28 Nov 2017, 04:46 last edited by dream_captain
                      #10

                      @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.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::Window and then remove Qt::WindowMinimizeButtonHint

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        Kucchan
                        wrote on 28 Nov 2017, 06:49 last edited by
                        #11

                        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.

                        D 1 Reply Last reply 28 Nov 2017, 07:02
                        0
                        • K Kucchan
                          28 Nov 2017, 06:49

                          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.

                          D Offline
                          D Offline
                          dream_captain
                          wrote on 28 Nov 2017, 07:02 last edited by
                          #12

                          @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?

                          K 1 Reply Last reply 29 Nov 2017, 03:46
                          1
                          • D dream_captain
                            28 Nov 2017, 07:02

                            @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?

                            K Offline
                            K Offline
                            Kucchan
                            wrote on 29 Nov 2017, 03:46 last edited by
                            #13

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

                            J 1 Reply Last reply 29 Nov 2017, 06:15
                            0
                            • K Kucchan
                              29 Nov 2017, 03:46

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

                              J Offline
                              J Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on 29 Nov 2017, 06:15 last edited by
                              #14

                              @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?).

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              2
                              • K Offline
                                K Offline
                                Kucchan
                                wrote on 4 Dec 2017, 00:52 last edited by
                                #15

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

                                D 1 Reply Last reply 4 Dec 2017, 04:34
                                0
                                • K Kucchan
                                  4 Dec 2017, 00:52

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

                                  D Offline
                                  D Offline
                                  dream_captain
                                  wrote on 4 Dec 2017, 04:34 last edited by
                                  #16

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

                                  K 1 Reply Last reply 5 Dec 2017, 05:01
                                  0
                                  • D dream_captain
                                    4 Dec 2017, 04:34

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

                                    K Offline
                                    K Offline
                                    Kucchan
                                    wrote on 5 Dec 2017, 05:01 last edited by
                                    #17

                                    @dream_captain

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

                                    1 Reply Last reply
                                    0
                                    • K Kucchan
                                      28 Nov 2017, 01:10

                                      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.ui

                                      main.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_OBJECT

                                      public:
                                      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.

                                      U Offline
                                      U Offline
                                      Ulises Galgo
                                      wrote on 4 Jan 2020, 20:52 last edited by
                                      #18

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

                                      1 Reply Last reply
                                      2

                                      • Login

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • Users
                                      • Groups
                                      • Search
                                      • Get Qt Extensions
                                      • Unsolved