I am attempting to add a “Full Screen” option to my Qt (using PyQt) application. If the user hits F11, the goal is to maximize the window.
I am having problems removing the window title bar though. Normally, I’d do something like self.setWindowFlags(QtCore.Qt.CustomizeWindowHint) in __init__ and the title bar would not display (expected behavior). However, if I launch the Qt application, and then wait for the user to press F11 like so:
def keyPressEvent(self, event):
if event.key() == QtCore.Qt.Key_F11:
self.__doFullScreenCheck()
def __doFullScreenCheck(self):
if self.maximizedFlg == False:
self.__maximizeWindow()
def __maximizeWindow(self):
***self.setWindowFlags(QtCore.Qt.CustomizeWindowHint)***
screen = QtGui.QDesktopWidget().screenGeometry()
self.setGeometry(screen)
self.maximizedFlg = True
Having the marked line in __maximizeWindow outside of __init__ seems to make the window completely vanish. The application is still running (seen in task manager), but I can’t switch back to it using Alt+Tab or Task Manager.
How can I change Window Flags on fly?
From the Qt documentation on QWidget::windowFlags:
So just add
self.show()afterself.setWindowFlags(...)and you’ll be fine.