FramelessWindowHint fails at runtime on MainWindow
-
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.
-
@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.
-
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();
-
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.
-
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 callsetWindowFlags(Qt::FramelessWindowHint)
it becomesWindow|FramelessWindowHint
(you can't really loose theWindow
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. -
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. -
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