Setting QWidget size

Rich Shepard rshepard at
Thu Apr 22 21:06:08 BST 2021

Looking in my two PyQt5 books and on the Web I'm not seeing how to
successfully set a QWidget main window's size. Test code attached.

The overall application will use a QMainWindow with a QTabWidget. Individual
pages have a QWidget as the container (unless my understanding is flawed).
I've tried to add width and height to the attached and it loads
without error, but as a very small window. My readings and web searches
haven't let me find the proper syntax to set a default initial window size
for each tab's contant to 800x600 (unless they need to be smaller to fit on
the QTabWidget in a QMainWindow.

I've also tried qtc.QSize(800,600) without success.

What's the proper syntax to open the test application at a size of 800x600?


-------------- next part --------------
#!/usr/bin/env python3

import sys

from PyQt5 import QtWidgets as qtw
from PyQt5 import QtGui as qtg
from PyQt5 import QtCore as qtc

class TestWindow(qtw.QWidget):
    def __init__(self):
        bio = qtw.QWidget(windowTitle='Test', width = 800, height = 600)
        # Layout
        container = qtw.QWidget(self)
        group1 = qtw.QGridLayout()

        savebutton = qtw.QPushButton('Save')
        group1.addWidget(savebutton, 0, 0)
        cancelbutton = qtw.QPushButton('Cancel')
        group1.addWidget(cancelbutton, 0, 1)

    # Methods
    def save(self):

    def cancel(self):

if __name__ == '__main__':
    app = qtw.QApplication(sys.argv)
    bio = TestWindow()

More information about the PyQt mailing list