May 2019
Intermediate to advanced
542 pages
13h 37m
English
When creating data-entry forms, it's common to have labels next to the input widgets they label. Qt provides a convenient two-column grid layout for this situation called QFormLayout.
Let's add a form layout to our GUI:
form_layout = qtw.QFormLayout() layout.addLayout(form_layout)
Adding widgets can be easily done with the addRow() method:
form_layout.addRow('Item 1', qtw.QLineEdit(self)) form_layout.addRow('Item 2', qtw.QLineEdit(self)) form_layout.addRow(qtw.QLabel('<b>This is a label-only row</b>'))
This convenience method takes a string and a widget and automatically creates the QLabel widget for the string. If passed only a single widget (such as a QLabel), the widget spans both columns. This can be useful for headings ...
Read now
Unlock full access