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. Disable close for fullscreen window on Windows ?
QtWS25 Last Chance

Disable close for fullscreen window on Windows ?

Scheduled Pinned Locked Moved Solved General and Desktop
closeeventclose windowwindowsubuntu
7 Posts 3 Posters 2.2k Views
  • 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.
  • R Offline
    R Offline
    R-P-H
    wrote on 16 Jun 2020, 20:05 last edited by
    #1

    Hi, I have a fullscreen window that the user should not be able to close using alt+f4 on a keyboard. I have tried the following 2 options:

    Option 1: Disable window close button.

    myWindow->setWindowFlags(windowFlags() &= ~Qt::WindowCloseButtonHint);
    

    This works fine on Ubuntu 16.04 but for some reason it does not work on WIndows ?

    Option 2: Overwrite closeEvent()

    void MyWindow::closeEvent (QCloseEvent *event)
    {
        event->ignore();
    }
    

    This works, however I need to call this->close() on certain events to close the window and overwriting closeEvent() stops this from working.

    Disabling the close button works fine for me except that it doesn't work on Windows ? Can this be fixed or are there any other options ? Thanks.

    C 1 Reply Last reply 16 Jun 2020, 20:28
    0
    • R R-P-H
      17 Jun 2020, 06:55

      @Chris-Kawa Thanks for that ! Would you say there's a more popular way of achieving this rather than adding a flag to all my classes ?

      C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 17 Jun 2020, 08:07 last edited by Chris Kawa
      #6

      @R-P-H said in Disable close for fullscreen window on Windows ?:

      Would you say there's a more popular way of achieving this rather than adding a flag to all my classes ?

      It's such a small problem I don't think there's any established pattern for this. The gist of it is that you want closeEvent to behave differently depending on the trigger for it so a flag to indicate that seems reasonable.

      If there's more than one such class you have you can make a base class with that functionality so that you don't copy/paste it everywhere. You could give it a custom closeInternal() method or something that you'd use from code and it would set the flag and then call close().

      If you don't want to add extra flag to your class you can use the built in dynamic properties of QObject and do something like this:

      void MyWindow::reallyClose()
      {
         setProperty("really_close", true);
         close();
      }
      
      void MyWindow::closeEvent(QCloseEvent* event)
      {
         if (!property("really_close").toBool())
             event->ignore();
      }
      
      R 1 Reply Last reply 17 Jun 2020, 09:09
      2
      • R R-P-H
        16 Jun 2020, 20:05

        Hi, I have a fullscreen window that the user should not be able to close using alt+f4 on a keyboard. I have tried the following 2 options:

        Option 1: Disable window close button.

        myWindow->setWindowFlags(windowFlags() &= ~Qt::WindowCloseButtonHint);
        

        This works fine on Ubuntu 16.04 but for some reason it does not work on WIndows ?

        Option 2: Overwrite closeEvent()

        void MyWindow::closeEvent (QCloseEvent *event)
        {
            event->ignore();
        }
        

        This works, however I need to call this->close() on certain events to close the window and overwriting closeEvent() stops this from working.

        Disabling the close button works fine for me except that it doesn't work on Windows ? Can this be fixed or are there any other options ? Thanks.

        C Offline
        C Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on 16 Jun 2020, 20:28 last edited by
        #2

        This works fine on Ubuntu 16.04 but for some reason it does not work on WIndows ?

        This is window manager specific. It might work on one and not on another, as you observed. It might not even work on another Linux system with different window manager.

        This works, however I need to call this->close() on certain events to close the window and overwriting closeEvent() stops this from working.

        Just add a boolean flag to your class indicating it's an internal call of yours and check it in the closeEvent.

        Btw. if you're making some sort of Kiosk application keep in mind that close button and system shortcut are just two of many many other ways to close a window so that's not even the minimum you need to do.

        R 1 Reply Last reply 17 Jun 2020, 06:55
        3
        • C Chris Kawa
          16 Jun 2020, 20:28

          This works fine on Ubuntu 16.04 but for some reason it does not work on WIndows ?

          This is window manager specific. It might work on one and not on another, as you observed. It might not even work on another Linux system with different window manager.

          This works, however I need to call this->close() on certain events to close the window and overwriting closeEvent() stops this from working.

          Just add a boolean flag to your class indicating it's an internal call of yours and check it in the closeEvent.

          Btw. if you're making some sort of Kiosk application keep in mind that close button and system shortcut are just two of many many other ways to close a window so that's not even the minimum you need to do.

          R Offline
          R Offline
          R-P-H
          wrote on 17 Jun 2020, 06:55 last edited by
          #3

          @Chris-Kawa Thanks for that ! Would you say there's a more popular way of achieving this rather than adding a flag to all my classes ?

          C 1 Reply Last reply 17 Jun 2020, 08:07
          0
          • G Offline
            G Offline
            gde23
            wrote on 17 Jun 2020, 07:36 last edited by
            #4

            If you want to remove all the buttons (also minimize) on top you could also remove the entire TitleBar, by setWindowFlags() to frameless window.
            However as Chris Kawa already mentioned the user will still be able to close the app by e.g. Alt+Tab to the Desktop and close it from the taskbar or by using the task manager or ...

            R 1 Reply Last reply 17 Jun 2020, 08:03
            0
            • G gde23
              17 Jun 2020, 07:36

              If you want to remove all the buttons (also minimize) on top you could also remove the entire TitleBar, by setWindowFlags() to frameless window.
              However as Chris Kawa already mentioned the user will still be able to close the app by e.g. Alt+Tab to the Desktop and close it from the taskbar or by using the task manager or ...

              R Offline
              R Offline
              R-P-H
              wrote on 17 Jun 2020, 08:03 last edited by
              #5

              @gde23 Yes I understand, thanks. That won't be suitable since the user will still be able to close via alt+f4.

              1 Reply Last reply
              0
              • R R-P-H
                17 Jun 2020, 06:55

                @Chris-Kawa Thanks for that ! Would you say there's a more popular way of achieving this rather than adding a flag to all my classes ?

                C Offline
                C Offline
                Chris Kawa
                Lifetime Qt Champion
                wrote on 17 Jun 2020, 08:07 last edited by Chris Kawa
                #6

                @R-P-H said in Disable close for fullscreen window on Windows ?:

                Would you say there's a more popular way of achieving this rather than adding a flag to all my classes ?

                It's such a small problem I don't think there's any established pattern for this. The gist of it is that you want closeEvent to behave differently depending on the trigger for it so a flag to indicate that seems reasonable.

                If there's more than one such class you have you can make a base class with that functionality so that you don't copy/paste it everywhere. You could give it a custom closeInternal() method or something that you'd use from code and it would set the flag and then call close().

                If you don't want to add extra flag to your class you can use the built in dynamic properties of QObject and do something like this:

                void MyWindow::reallyClose()
                {
                   setProperty("really_close", true);
                   close();
                }
                
                void MyWindow::closeEvent(QCloseEvent* event)
                {
                   if (!property("really_close").toBool())
                       event->ignore();
                }
                
                R 1 Reply Last reply 17 Jun 2020, 09:09
                2
                • C Chris Kawa
                  17 Jun 2020, 08:07

                  @R-P-H said in Disable close for fullscreen window on Windows ?:

                  Would you say there's a more popular way of achieving this rather than adding a flag to all my classes ?

                  It's such a small problem I don't think there's any established pattern for this. The gist of it is that you want closeEvent to behave differently depending on the trigger for it so a flag to indicate that seems reasonable.

                  If there's more than one such class you have you can make a base class with that functionality so that you don't copy/paste it everywhere. You could give it a custom closeInternal() method or something that you'd use from code and it would set the flag and then call close().

                  If you don't want to add extra flag to your class you can use the built in dynamic properties of QObject and do something like this:

                  void MyWindow::reallyClose()
                  {
                     setProperty("really_close", true);
                     close();
                  }
                  
                  void MyWindow::closeEvent(QCloseEvent* event)
                  {
                     if (!property("really_close").toBool())
                         event->ignore();
                  }
                  
                  R Offline
                  R Offline
                  R-P-H
                  wrote on 17 Jun 2020, 09:09 last edited by
                  #7

                  @Chris-Kawa Thanks, it works !

                  1 Reply Last reply
                  0

                  1/7

                  16 Jun 2020, 20:05

                  • Login

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