Qt 6.12 LTS is out! See what's new in the release
blog
QWidget modification at runtime
-
I am trying to make the ui elements of my window resize according to the window size but all the QWidgets stay the same size.
I have them all in a Horizontal Layout with their sizePolicies set appropriately. Here is my code for resizing the window and widgets:monitor = screeninfo.get_monitors()[0] x = monitor.width y = monitor.height class mainWindow(QtWidgets.QMainWindow): def __init__(self): super(mainWindow, self).__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) def refreshWindow(): # pass xn = window.width() yn = window.height() # TODO window.ui.toolList.resize(toolsScale * xn, toolsScale * yn) window.ui.imageViewer.resize(mainScale * xn, mainScale * yn) window.ui.layerList.resize(layersScale * xn, layersScale * yn) # listX = (toolsScale + mainScale) * xn # window.ui.layerList.move(listX, 0) print(window.ui.layerList.pos()) window.ui.layerList.show() # Resize window and its elements to fit the screen window.show() # Function to refresh window elements global window if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) global window window = mainWindow() window.resize(x, y) refreshWindow() window.show() # Load main window sys.exit(app.exec()) -
Hi,
Since you have a QMainWindow, is your layout applied to the central widget of your QMainWindow ? Or did you try to change the QMainWindow's own layout which is not possible.