PyQt5: nested layouts
Rich Shepard
rshepard at appl-ecosys.com
Thu Apr 29 22:38:55 BST 2021
I thought that I understood how to nest layouts, but I'm getting an error:
$ python test.py
QLayout: Attempting to add QLayout "" to TestWindow "", which already has a layout
When the test.py module used a grid layout with a container named,
'container', there was no problem. But, trying to replace the grid with a
series of QHBoxLayout within a QVBoxLayout the above warning displays. I'm
not seeing why. The test.py file is attached.
Please show me what I've done incorrectly.
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__()
test = qtw.QWidget(windowTitle='Testing')
# Layout
inner = qtw.QVBoxLayout(self)
self.setLayout(inner)
row1 = qtw.QHBoxLayout(self)
inner.addLayout(row1)
id_label = qtw.QLabel('Site ID', self)
row1.addWidget(id_label)
id_nbr = qtw.QLineEdit(self,
clearButtonEnabled = True,
maxLength = 16
)
row1.addWidget(id_nbr)
site_name_label = qtw.QLabel('Site Name', self)
row1.addWidget(site_name_label)
site_name = qtw.QLineEdit(self,
clearButtonEnabled = True,
maxLength = 64
)
row1.addWidget(site_name)
self.show()
# Methods
def save(self):
pass
def cancel(save):
pass
if __name__ == '__main__':
app = qtw.QApplication(sys.argv)
test = TestWindow()
sys.exit(app.exec())
More information about the PyQt
mailing list