Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How we can disable the close [X] button in the top right corner of GUI?
Forum Updated to NodeBB v4.3 + New Features

How we can disable the close [X] button in the top right corner of GUI?

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 6 Posters 7.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.
  • C Offline
    C Offline
    Chrisw01
    wrote on last edited by Chrisw01
    #4

    @Mijaz Hi,

    You can also override the QClose Event to handle it. Thus giving you the option to pop up a "Are you sure" box, or send the mainform to the hidden taskbar area, or just ignore the event all together.

    1 Reply Last reply
    1
    • Gojir4G Gojir4

      @Mijaz Hi,

      Add setWindowsFlags(Qt::WindowCloseButtonHint, false); in your widget's constructor

      MijazM Offline
      MijazM Offline
      Mijaz
      wrote on last edited by Mijaz
      #5

      @Gojir4 @Chrisw01
      where should I add this line exectly?
      setWindowsFlags(Qt::WindowCloseButtonHint, false);

      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      
      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      
      
      {
          ui->setupUi(this);
      
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      
      void MainWindow::on_pushButton_clicked()
      {
       ui->textEdit->setText("this is for test");
      }
      
      

      Selection_038.png

      jsulmJ Gojir4G 2 Replies Last reply
      0
      • MijazM Mijaz

        @Gojir4 @Chrisw01
        where should I add this line exectly?
        setWindowsFlags(Qt::WindowCloseButtonHint, false);

        #include "mainwindow.h"
        #include "ui_mainwindow.h"
        
        MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow)
        
        
        {
            ui->setupUi(this);
        
        }
        
        MainWindow::~MainWindow()
        {
            delete ui;
        }
        
        void MainWindow::on_pushButton_clicked()
        {
         ui->textEdit->setText("this is for test");
        }
        
        

        Selection_038.png

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by jsulm
        #6

        @Mijaz Please read again what @Gojir4 wrote:
        "Add setWindowsFlags(Qt::WindowCloseButtonHint, false); in your widget's constructor"

        https://doc.qt.io/qt-5/qtwidgets-widgets-windowflags-example.html

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

        1 Reply Last reply
        2
        • MijazM Mijaz

          @Gojir4 @Chrisw01
          where should I add this line exectly?
          setWindowsFlags(Qt::WindowCloseButtonHint, false);

          #include "mainwindow.h"
          #include "ui_mainwindow.h"
          
          MainWindow::MainWindow(QWidget *parent) :
              QMainWindow(parent),
              ui(new Ui::MainWindow)
          
          
          {
              ui->setupUi(this);
          
          }
          
          MainWindow::~MainWindow()
          {
              delete ui;
          }
          
          void MainWindow::on_pushButton_clicked()
          {
           ui->textEdit->setText("this is for test");
          }
          
          

          Selection_038.png

          Gojir4G Offline
          Gojir4G Offline
          Gojir4
          wrote on last edited by
          #7

          @Mijaz

          MainWindow::MainWindow(QWidget *parent) :
              QMainWindow(parent), ui(new Ui::MainWindow)
          {
              ui->setupUi(this);
              setWindowsFlags(Qt::WindowCloseButtonHint, false);
          }
          
          MijazM 2 Replies Last reply
          0
          • Gojir4G Gojir4

            @Mijaz

            MainWindow::MainWindow(QWidget *parent) :
                QMainWindow(parent), ui(new Ui::MainWindow)
            {
                ui->setupUi(this);
                setWindowsFlags(Qt::WindowCloseButtonHint, false);
            }
            
            MijazM Offline
            MijazM Offline
            Mijaz
            wrote on last edited by Mijaz
            #8

            @Gojir4
            Hi,
            I am using qt4.8.7.
            your suggested command not working.

            #include "mainwindow.h"
            #include "ui_mainwindow.h"
            #include <QDebug>
            
            MainWindow::MainWindow(QWidget *parent) :
                QMainWindow(parent),
                ui(new Ui::MainWindow)
            {
                ui->setupUi(this);
               setWindowFlags(Qt::WindowCloseButtonHint, false);
                timerId = startTimer(1000);
            }
            MainWindow::~MainWindow()
            {
                killTimer(timerId);
                delete ui;
            }
            void MainWindow::timerEvent(QTimerEvent *event)
            {
                qDebug() << "Update...";
                ui->lineEdit->setText("test  ");
            }
            

            Selection_039.png

            jsulmJ J.HilkJ 2 Replies Last reply
            0
            • MijazM Mijaz

              @Gojir4
              Hi,
              I am using qt4.8.7.
              your suggested command not working.

              #include "mainwindow.h"
              #include "ui_mainwindow.h"
              #include <QDebug>
              
              MainWindow::MainWindow(QWidget *parent) :
                  QMainWindow(parent),
                  ui(new Ui::MainWindow)
              {
                  ui->setupUi(this);
                 setWindowFlags(Qt::WindowCloseButtonHint, false);
                  timerId = startTimer(1000);
              }
              MainWindow::~MainWindow()
              {
                  killTimer(timerId);
                  delete ui;
              }
              void MainWindow::timerEvent(QTimerEvent *event)
              {
                  qDebug() << "Update...";
                  ui->lineEdit->setText("test  ");
              }
              

              Selection_039.png

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #9

              @Mijaz Please read documentation: https://doc.qt.io/qt-5/qwidget.html#windowFlags-prop

              setWindowFlags(windowFlags() & ~Qt::WindowCloseButtonHint);
              

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

              1 Reply Last reply
              3
              • MijazM Mijaz

                @Gojir4
                Hi,
                I am using qt4.8.7.
                your suggested command not working.

                #include "mainwindow.h"
                #include "ui_mainwindow.h"
                #include <QDebug>
                
                MainWindow::MainWindow(QWidget *parent) :
                    QMainWindow(parent),
                    ui(new Ui::MainWindow)
                {
                    ui->setupUi(this);
                   setWindowFlags(Qt::WindowCloseButtonHint, false);
                    timerId = startTimer(1000);
                }
                MainWindow::~MainWindow()
                {
                    killTimer(timerId);
                    delete ui;
                }
                void MainWindow::timerEvent(QTimerEvent *event)
                {
                    qDebug() << "Update...";
                    ui->lineEdit->setText("test  ");
                }
                

                Selection_039.png

                J.HilkJ Online
                J.HilkJ Online
                J.Hilk
                Moderators
                wrote on last edited by J.Hilk
                #10

                @Mijaz said in

                button in the top right corner of GUI?
                :

                I am using qt4.8.7.

                Important information, that one should state in the opening post.

                besides that, looking into the Qt4 Documentation shows the following:
                https://doc.qt.io/archives/qt-4.8/qwidget.html#windowFlags-prop
                with an actual example on how top use it:
                https://doc.qt.io/archives/qt-4.8/qt-widgets-windowflags-example.html

                ->

                setWindowFlags(windowFlags()  & ~Qt::WindowCloseButtonHint); 
                

                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                4
                • Gojir4G Gojir4

                  @Mijaz

                  MainWindow::MainWindow(QWidget *parent) :
                      QMainWindow(parent), ui(new Ui::MainWindow)
                  {
                      ui->setupUi(this);
                      setWindowsFlags(Qt::WindowCloseButtonHint, false);
                  }
                  
                  MijazM Offline
                  MijazM Offline
                  Mijaz
                  wrote on last edited by
                  #11

                  @Gojir4
                  Now this is working

                  {
                      ui->setupUi(this);
                  
                      timerId = startTimer(1000);
                      this->setWindowFlags(Qt::WindowMaximizeButtonHint);
                  }
                  

                  Selection_041.png

                  J.HilkJ jsulmJ 2 Replies Last reply
                  0
                  • MijazM Mijaz

                    @Gojir4
                    Now this is working

                    {
                        ui->setupUi(this);
                    
                        timerId = startTimer(1000);
                        this->setWindowFlags(Qt::WindowMaximizeButtonHint);
                    }
                    

                    Selection_041.png

                    J.HilkJ Online
                    J.HilkJ Online
                    J.Hilk
                    Moderators
                    wrote on last edited by
                    #12

                    @Mijaz great
                    just a warning, since you're on linux. Not every WindowManager will support the individual showing/hiding of Window-Buttons


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    MijazM 1 Reply Last reply
                    2
                    • MijazM Mijaz

                      @Gojir4
                      Now this is working

                      {
                          ui->setupUi(this);
                      
                          timerId = startTimer(1000);
                          this->setWindowFlags(Qt::WindowMaximizeButtonHint);
                      }
                      

                      Selection_041.png

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #13

                      @Mijaz said in

                      button in the top right corner of GUI?
                      :

                      this->setWindowFlags(Qt::WindowMaximizeButtonHint);

                      Keep in mind that this way you disable all other flags. But as long as this is fine for you you can do it this way.

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

                      1 Reply Last reply
                      1
                      • J.HilkJ J.Hilk

                        @Mijaz great
                        just a warning, since you're on linux. Not every WindowManager will support the individual showing/hiding of Window-Buttons

                        MijazM Offline
                        MijazM Offline
                        Mijaz
                        wrote on last edited by
                        #14

                        @J-Hilk
                        yes, When I deploy it to the board then it still showing the close mark.

                        How I can remove this permanently?

                        J.HilkJ 1 Reply Last reply
                        0
                        • MijazM Mijaz

                          @J-Hilk
                          yes, When I deploy it to the board then it still showing the close mark.

                          How I can remove this permanently?

                          J.HilkJ Online
                          J.HilkJ Online
                          J.Hilk
                          Moderators
                          wrote on last edited by
                          #15

                          @Mijaz change the window manager on the board...

                          Here a guide, on how to do it on GNOME, should be similar for all Linux flavors
                          https://linuxcommando.blogspot.com/2014/07/how-to-change-window-manager-for-gnome.html


                          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                          Q: What's that?
                          A: It's blue light.
                          Q: What does it do?
                          A: It turns blue.

                          MijazM 1 Reply Last reply
                          1
                          • J.HilkJ J.Hilk

                            @Mijaz change the window manager on the board...

                            Here a guide, on how to do it on GNOME, should be similar for all Linux flavors
                            https://linuxcommando.blogspot.com/2014/07/how-to-change-window-manager-for-gnome.html

                            MijazM Offline
                            MijazM Offline
                            Mijaz
                            wrote on last edited by
                            #16

                            @J-Hilk
                            Now I have removed the title bar. and its working on board also.

                                setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowTitleHint);
                            
                            
                            1 Reply Last reply
                            0

                            • Login

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