Setting QWidget size
Rodrigo de Salvo Braz
rodrigobraz at gmail.com
Thu Apr 22 22:24:51 BST 2021
PS: I thought you wanted just the container to show completely. If you want
the window to really have a fixed size, you can use
self.setFixedSize(800, 600)
Rodrigo
On Thu, Apr 22, 2021 at 2:22 PM Rodrigo de Salvo Braz <rodrigobraz at gmail.com>
wrote:
> Hi Rich,
>
> 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.
>
> Rodrigo
>
> #!/usr/bin/env python3
>
> import sys
>
> from PyQt5 import QtWidgets as qtw
> from PyQt5 import QtGui as qtg
> from PyQt5 import QtCore as qtc
> from PyQt5.QtWidgets import QMainWindow
>
>
> class TestWindow(QMainWindow):
> def __init__(self):
> super().__init__()
> bio = qtw.QWidget(windowTitle='Test', width = 800, height = 600)
>
> # Layout
> container = qtw.QWidget(self)
> group1 = qtw.QGridLayout()
> container.setLayout(group1)
>
> savebutton = qtw.QPushButton('Save')
> savebutton.clicked.connect(self.save)
> group1.addWidget(savebutton, 0, 0)
>
> cancelbutton = qtw.QPushButton('Cancel')
> cancelbutton.clicked.connect(self.cancel)
> group1.addWidget(cancelbutton, 0, 1)
>
> self.setCentralWidget(container)
>
> self.show()
>
> # Methods
> def save(self):
> pass
>
> def cancel(self):
> pass
>
>
> if __name__ == '__main__':
> app = qtw.QApplication(sys.argv)
> bio = TestWindow()
> sys.exit(app.exec())
>
>
>
> On Thu, Apr 22, 2021 at 1:06 PM Rich Shepard <rshepard at appl-ecosys.com>
> wrote:
>
>> 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 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?
>>
>> TIA,
>>
>> Rich
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20210422/f9e56743/attachment.htm>
More information about the PyQt
mailing list