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 to disable 'x' close button
Forum Updated to NodeBB v4.3 + New Features

How to disable 'x' close button

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 6.0k 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.
  • N Offline
    N Offline
    nicholaslee
    wrote on last edited by
    #1
    this->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint);
    

    I tried this but it doesn't work. The reason why i want to disable it is because my app downloads files and if the user closes window 1 before the download finishes, window 2 lags and crashes. Only happens during download.

    J.HilkJ raven-worxR 2 Replies Last reply
    0
    • N nicholaslee
      this->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint);
      

      I tried this but it doesn't work. The reason why i want to disable it is because my app downloads files and if the user closes window 1 before the download finishes, window 2 lags and crashes. Only happens during download.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      hi @nicholaslee
      the easiest would probably be to overwride the close event. something like this:

      adjusted from the Application Example

      void MainWindow::closeEvent(QCloseEvent *event)
      {
          if (downloadOngoing()) {
              event->ignore()
          } else {
              event->accept();
          }
      }
      

      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
      2
      • N nicholaslee
        this->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint);
        

        I tried this but it doesn't work. The reason why i want to disable it is because my app downloads files and if the user closes window 1 before the download finishes, window 2 lags and crashes. Only happens during download.

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        @nicholaslee
        when do you call this method exactly?

        What happens with this:

        this->setWindowFlags( (Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint) & ~Qt::WindowCloseButtonHint );
        

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nicholaslee
          wrote on last edited by
          #4

          @J-Hilk I just tried closeevent but oops i already used it and when i build it again qt says closeevent cannot be overloaded.

          @raven-worx

          DownloaderUI::DownloaderUI(QWidget *parent) :
              QDialog(parent),
              ui(new Ui::DownloaderUI)
          {
              ui->setupUi(this);
              this->setWindowTitle("    Offline IVLE");
              this->setWindowIcon(QPixmap(":/icons/OIVLE.png"));
              this->setWindowFlags( (Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint) & ~Qt::WindowCloseButtonHint );
          
          
          

          I am calling it in my constructor when i setup the ui. My window title and icon works but the setwindowsflag does nothing. No difference in my app.

          Thank you all for helping!

          raven-worxR jsulmJ 2 Replies Last reply
          0
          • N nicholaslee

            @J-Hilk I just tried closeevent but oops i already used it and when i build it again qt says closeevent cannot be overloaded.

            @raven-worx

            DownloaderUI::DownloaderUI(QWidget *parent) :
                QDialog(parent),
                ui(new Ui::DownloaderUI)
            {
                ui->setupUi(this);
                this->setWindowTitle("    Offline IVLE");
                this->setWindowIcon(QPixmap(":/icons/OIVLE.png"));
                this->setWindowFlags( (Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint) & ~Qt::WindowCloseButtonHint );
            
            
            

            I am calling it in my constructor when i setup the ui. My window title and icon works but the setwindowsflag does nothing. No difference in my app.

            Thank you all for helping!

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            @nicholaslee
            on what system are you actually on?

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • N nicholaslee

              @J-Hilk I just tried closeevent but oops i already used it and when i build it again qt says closeevent cannot be overloaded.

              @raven-worx

              DownloaderUI::DownloaderUI(QWidget *parent) :
                  QDialog(parent),
                  ui(new Ui::DownloaderUI)
              {
                  ui->setupUi(this);
                  this->setWindowTitle("    Offline IVLE");
                  this->setWindowIcon(QPixmap(":/icons/OIVLE.png"));
                  this->setWindowFlags( (Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint) & ~Qt::WindowCloseButtonHint );
              
              
              

              I am calling it in my constructor when i setup the ui. My window title and icon works but the setwindowsflag does nothing. No difference in my app.

              Thank you all for helping!

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

              @nicholaslee said in How to disable 'x' close button:

              closeevent cannot be overloaded

              You need to override it not overload

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

              1 Reply Last reply
              2
              • N Offline
                N Offline
                nicholaslee
                wrote on last edited by
                #7

                @raven-worx
                I am on windows, qt5.0.2, creator 4.6.2.

                @jsulm @J-Hilk Noted. Actually how do I check if there is a downloadongoing? My download is set using a timer. Every hour it downloads. I tried to key in the code below, i added xxxx=1 at the top of my download function and xxxx=0 at the end of it. My app crashes instead.

                void IVLEFetcher::closeEvent(QCloseEvent *event){
                    if (xxxx==0){
                        event->accept();
                    } else {
                        if (xxxx==1){
                            event->ignore();
                        }
                    }
                }
                
                jsulmJ 1 Reply Last reply
                0
                • N nicholaslee

                  @raven-worx
                  I am on windows, qt5.0.2, creator 4.6.2.

                  @jsulm @J-Hilk Noted. Actually how do I check if there is a downloadongoing? My download is set using a timer. Every hour it downloads. I tried to key in the code below, i added xxxx=1 at the top of my download function and xxxx=0 at the end of it. My app crashes instead.

                  void IVLEFetcher::closeEvent(QCloseEvent *event){
                      if (xxxx==0){
                          event->accept();
                      } else {
                          if (xxxx==1){
                              event->ignore();
                          }
                      }
                  }
                  
                  jsulmJ Online
                  jsulmJ Online
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @nicholaslee said in How to disable 'x' close button:

                  My app crashes instead

                  Where does it crash? Did you debug?

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

                  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