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. FramelessWindowHint fails at runtime on MainWindow
Forum Updated to NodeBB v4.3 + New Features

FramelessWindowHint fails at runtime on MainWindow

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 8.8k Views 2 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.
  • R Offline
    R Offline
    Rory_1
    wrote on 13 Nov 2015, 18:01 last edited by
    #1

    When I execute setWindowFlags(Qt::FramelessWindowHint) before the main window is shown this works, but if I try to execute after the main window is shown the window disappears from the screen and the task manager but is still running. I have to kill it in Qt Creator using the stop button.

    Here is some test code:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        // ui is vanilla window with one pushbutton
        ui->setupUi(this);
    
        // works here before window shows
        // setWindowFlags(Qt::FramelessWindowHint);
    }
    
    void MainWindow::on_pushButton_clicked()
    {
        // causes window to disappear and not visible in task
        // manager but it is still running
        setWindowFlags(Qt::FramelessWindowHint);
    }
    

    Qt 5.5 on Windows 10

    Any help is much appreciated!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 13 Nov 2015, 19:11 last edited by
      #2

      @Rory_1 said:

      Qt::FramelessWindowHint

      Might be bug in newer version
      https://forum.qt.io/topic/53502/toggle-window-frames-qt-framelesswindowhint-in-qt-5-4-1

      why cant you just set in constructor ?
      need to toggle it ?

      R 1 Reply Last reply 13 Nov 2015, 19:45
      0
      • M mrjj
        13 Nov 2015, 19:11

        @Rory_1 said:

        Qt::FramelessWindowHint

        Might be bug in newer version
        https://forum.qt.io/topic/53502/toggle-window-frames-qt-framelesswindowhint-in-qt-5-4-1

        why cant you just set in constructor ?
        need to toggle it ?

        R Offline
        R Offline
        Rory_1
        wrote on 13 Nov 2015, 19:45 last edited by
        #3

        @mrjj

        Yes, I want to toggle.

        M 1 Reply Last reply 13 Nov 2015, 20:11
        0
        • R Rory_1
          13 Nov 2015, 19:45

          @mrjj

          Yes, I want to toggle.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 13 Nov 2015, 20:11 last edited by
          #4

          @Rory_1
          ok. i get same result on win 7, qt 5.5 so its a bug it seems.

          there is showFullScreen(); if you need for something like that.

          can I ask what case you need borderless window for?

          R 1 Reply Last reply 13 Nov 2015, 21:12
          0
          • M mrjj
            13 Nov 2015, 20:11

            @Rory_1
            ok. i get same result on win 7, qt 5.5 so its a bug it seems.

            there is showFullScreen(); if you need for something like that.

            can I ask what case you need borderless window for?

            R Offline
            R Offline
            Rory_1
            wrote on 13 Nov 2015, 21:12 last edited by Rory_1
            #5

            @mrjj

            Mainly for ascetics and screen real estate. I am building a raw image viewer and want to be able to toggle to a slideshow view to maximize the image size. When viewing images vertical space is always at a premium for portrait oriented images, so anything I can eliminate is helpful.

            M 1 Reply Last reply 13 Nov 2015, 22:11
            0
            • R Rory_1
              13 Nov 2015, 21:12

              @mrjj

              Mainly for ascetics and screen real estate. I am building a raw image viewer and want to be able to toggle to a slideshow view to maximize the image size. When viewing images vertical space is always at a premium for portrait oriented images, so anything I can eliminate is helpful.

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 13 Nov 2015, 22:11 last edited by
              #6

              @mrjj said:

              well I assume fullscreen is too drastic ?

              One option you have is to use a dialog for viewing the image. When change to borderless mode, you can simply
              create a new instance where you set the flag in the constructor. (and delete the old one)

              It would also be possible to do this with mainwindow from main, but would be slightly more haxish.

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Chris Kawa
                Lifetime Qt Champion
                wrote on 14 Nov 2015, 12:07 last edited by
                #7

                That's not a bug. That's just how window managers work. You shouldn't change the frame on a visible window.
                And btw. you should just add the hint, not replace all of them i.e. to make it frameless:

                hide();
                setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
                show();
                

                and to go back:

                hide();
                setWindowFlags(windowFlags() & ~Qt::FramelessWindowHint);
                show();
                
                R 1 Reply Last reply 14 Nov 2015, 17:09
                3
                • M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 14 Nov 2015, 12:42 last edited by
                  #8

                  setWindowFlags(windowFlags() | Qt::FramelessWindowHint);

                  So clear when you see it :)

                  Can you tell why it does seem work in ctor after ui setup
                  setWindowFlags(Qt::FramelessWindowHint);

                  Even if not OR ing.

                  1 Reply Last reply
                  1
                  • C Offline
                    C Offline
                    Chris Kawa
                    Lifetime Qt Champion
                    wrote on 14 Nov 2015, 12:57 last edited by Chris Kawa
                    #9

                    Can you tell why it does seem work in ctor after ui setup

                    It's an (un)fortunate coincidence. The default flags are something like:
                    Window|WindowTitleHint|WindowSystemMenuHint|WindowMinMaxButtonsHint|WindowCloseButtonHint|WindowFullscreenButtonHint
                    If you call setWindowFlags(Qt::FramelessWindowHint) it becomes Window|FramelessWindowHint (you can't really loose the Window flag), so you loose all the hint flags. It seems to work, since frameless window doesn't use them anyway, but if you tried to go back or if somebody set some other flags (either with setWindowFlags or via the second param of QWidget's constructor) you'd loose them and had no way to know what they were.

                    As to why did the setWindowFlags call seem to work in the constructor and didn't later, it's because when a constructor is run the widget is not yet shown, so changing flags is ok there.

                    1 Reply Last reply
                    1
                    • M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 14 Nov 2015, 13:04 last edited by
                      #10

                      Ah so cannot really clear the Window flag and hence we see no ill effect when only using the default values.
                      So always OR. Even in ctor.

                      1 Reply Last reply
                      0
                      • C Chris Kawa
                        14 Nov 2015, 12:07

                        That's not a bug. That's just how window managers work. You shouldn't change the frame on a visible window.
                        And btw. you should just add the hint, not replace all of them i.e. to make it frameless:

                        hide();
                        setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
                        show();
                        

                        and to go back:

                        hide();
                        setWindowFlags(windowFlags() & ~Qt::FramelessWindowHint);
                        show();
                        
                        R Offline
                        R Offline
                        Rory_1
                        wrote on 14 Nov 2015, 17:09 last edited by
                        #11

                        @Chris-Kawa

                        Thanks so much Chris for the solution and the clear explanation. Sorry about my inexperience, but how do I show the issue has been solved?

                        Best regards
                        Rory

                        M 1 Reply Last reply 14 Nov 2015, 17:26
                        0
                        • R Rory_1
                          14 Nov 2015, 17:09

                          @Chris-Kawa

                          Thanks so much Chris for the solution and the clear explanation. Sorry about my inexperience, but how do I show the issue has been solved?

                          Best regards
                          Rory

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 14 Nov 2015, 17:26 last edited by mrjj
                          #12

                          @Rory_1
                          hi
                          Use the Topic Tools button to mark as Solved.
                          its sort below topic/post to the right.

                          R 1 Reply Last reply 14 Nov 2015, 18:02
                          0
                          • M mrjj
                            14 Nov 2015, 17:26

                            @Rory_1
                            hi
                            Use the Topic Tools button to mark as Solved.
                            its sort below topic/post to the right.

                            R Offline
                            R Offline
                            Rory_1
                            wrote on 14 Nov 2015, 18:02 last edited by
                            #13

                            @mrjj Thanks!

                            1 Reply Last reply
                            0

                            4/13

                            13 Nov 2015, 20:11

                            9 unread
                            • Login

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