-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.7.3, 6.9.1
-
None
I wrote a minimal example where a simple window can be toggled between fullscreen and how it was shown before.
This works in general, but when the window is maximized and then set to fullscreen the window is behaving irritating by switching to "normal" for a moment and then the animation to maximized is started.
FullscreenableWidget.hpp
#include <QWidget> #include <QShortcut> class FullscreenableWidget : public QWidget { public: FullscreenableWidget() { const auto stdFS = new QShortcut{ QKeySequence::FullScreen, this }; connect(stdFS, &QShortcut::activated, this, &FullscreenableWidget::toggleFullScreen); } private slots: void toggleFullScreen() { if(!isFullScreen()) { m_prevState = windowState(); if(!isMaximized()) { m_prevGeometry = geometry(); } showFullScreen(); } else { if(m_prevState.testFlag(Qt::WindowMaximized)) { showMaximized(); } else if(m_prevGeometry.isValid()) { showNormal(); setGeometry(m_prevGeometry); } } } Qt::WindowStates m_prevState{ Qt::WindowNoState }; QRect m_prevGeometry; };
main.cpp
#include <QApplication> #include "FullscreenableWidget.hpp" int main(int argc, char* argv[]) { QApplication app(argc, argv); FullscreenableWidget window; window.show(); return app.exec(); }