My layout understanding needs improvement

Rich Shepard rshepard at appl-ecosys.com
Thu Apr 22 17:22:28 BST 2021


My test code (really attached this time) displays when run, but with this
message on the console:
$ python test.py 
QWidget::setLayout: Attempting to set QLayout "" on TestWindow "", which already has a
layout

In my newness to PyQt I do not see where I've duplicated an unnecessary
layout call. I need to learn this to move on to better presenting the
displayed layout.

Thanks in advance,

Rich
-------------- 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):
        super().__init__()
        bio = qtw.QWidget(windowTitle='Test')

        # Layout
        group1 = qtw.QVBoxLayout()
        self.setLayout(group1)

        button_row = qtw.QHBoxLayout()
        self.setLayout(button_row)
        
        self.savebutton = qtw.QPushButton('Save')
        self.savebutton.clicked.connect(self.save)
        button_row.addWidget(self.savebutton)
        
        self.cancelbutton = qtw.QPushButton('Cancel')
        self.cancelbutton.clicked.connect(self.cancel)
        button_row.addWidget(self.cancelbutton)

        group1.addLayout(button_row)
        
        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())       


More information about the PyQt mailing list