Setting QWidget size
Rodrigo de Salvo Braz
rodrigobraz at gmail.com
Thu Apr 22 22:22:39 BST 2021
It seems your object 'bio' is not being used after creation so it won't
have an effect.
I've changed your code to subclass from QMainWindow, and added a statement
self.setCentralWidget(container), and it now seem to be doing what you
want. Please let me know if that's not true.
from PyQt5 import QtWidgets as qtw
from PyQt5 import QtGui as qtg
from PyQt5 import QtCore as qtc
from PyQt5.QtWidgets import QMainWindow
bio = qtw.QWidget(windowTitle='Test', width = 800, height = 600)
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)
if __name__ == '__main__':
app = qtw.QApplication(sys.argv)
bio = TestWindow()
On Thu, Apr 22, 2021 at 1:06 PM Rich Shepard <rshepard at appl-ecosys.com>
> 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.
> pages have a QWidget as the container (unless my understanding is flawed).
> I've tried to add width and height to the attached testgrid.py 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 --------------
An HTML attachment was scrubbed...
More information about the PyQt