Unsolved Can a single widget be made to go full-screen, without making the whole window fullscreen?
-
Hello
I'm wondering if it's possible to make a single widget temporarily go full-screen in my PyQt5 application, without fullscreening the whole of the window that contains the widget.
In my tests the answer would appear to be "no" but I was wondering if maybe I'm doing something wrong, or if there's a workaround that might be applicable for this.
I've pasted some example code below. The form looks like this:
What I would like is for the 'full-screen test' button to make the button and the "Label on inner layout" go full-screen, but the "Label on outer layout" should NOT be visible- so only the inner layout goes full-screen.
Can this be done at all, and if so, why is it not working in my code please?
import sys from PyQt5.QtWidgets import QApplication, QDialog, QPushButton, QLabel, QGridLayout, QFrame from PyQt5.QtCore import Qt class FullScreenTest(QDialog): def __init__(self): super().__init__() self.setWindowFlags(Qt.WindowCloseButtonHint | Qt.WindowType_Mask) self.title = 'PyQt5 tests' self.outerLayout = QGridLayout(self) self.innerLayout = QGridLayout() self.button = QPushButton("Full-screen test") self.innerLayout.addWidget(self.button, 0, 0) self.innerLayout.addWidget(QLabel("Label on inner layout"), 0, 1) self.innerLayout_frame = QFrame() self.innerLayout_frame.setLayout(self.innerLayout) self.outerLayout.addWidget(self.innerLayout_frame, 0, 0) self.outerLayout.addWidget(QLabel("Label on outer layout"), 1, 0) self.button.clicked.connect(lambda: switch_fullscreen(self.innerLayout_frame)) self.show() def switch_fullscreen(targetWidget): if targetWidget.isFullScreen(): targetWidget.showNormal() print("Showing normal.") else: targetWidget.showFullScreen() print("Showing fullscreen.") if __name__ == '__main__': app = QApplication(sys.argv) ex = FullScreenTest() sys.exit(app.exec_())
-
Perhaps this may help, or at least be a starting point
https://forum.qt.io/topic/23308/how-to-fullscreen-the-child-widget
or this other too
https://stackoverflow.com/questions/1246825/fullscreen-widget -
Hi,
You have to remove the widget from the layout containing it and then you can make it fullscreen. You will also have to put it back in place once you get out of fullscreen mode.
-
@SGaist Thanks very much for this explanation. After a bit of fiddling with adjusting fixedWidths and so on, I've now got this working exactly as I was hoping.
-
Great !
Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that's other forum users may know a solution has been found :-)