
- PyQt - Home
- PyQt - Introduction
- PyQt - Environment
- PyQt - Hello World
- PyQt - Major Classes
- PyQt - Using Qt Designer
- PyQt - Meta Objects
- PyQt Signals & Slots
- PyQt - Signals and Slots
- PyQt - Support and Signals
- PyQt - Unbound and Bound Signals
- PyQt - New Signals with PyQtSignal
- PyQt - Connecting, Disconnecting, & Emitting Signals
- PyQt - Slot decorator
- PyQt - Slot Connection
- PyQt Layouts
- PyQt - Layout Management
- PyQt - QBoxLayout
- PyQt - QGridLayout
- PyQt - QFormLayout
- PyQt - QHBoxLayout
- PyQt - QVBoxLayout
- PyQt - QStackedLayout
- PyQt - QGraphicsGridLayout
- PyQt - QGraphicsAnchorLayout
- PyQt - QGraphicsLayout
- PyQt - QGraphicsLinearLayout
- PyQt Basic Widgets
- PyQt - Basic Widgets
- PyQt - Qlabel Widget
- PyQt - QLineEdit Widget
- PyQt - QPushButton Widget
- PyQt - QRadioButton Widget
- PyQt - QCheckBox Widget
- PyQt - QComboBox Widget
- PyQt - QSpinBox Widget
- PyQt - QMessageBox
- PyQt - QDialogButtonBox Widget
- PyQt - QFontComboBox Widget
- PyQt - QDoubleSpinBox Widget
- PyQt - QToolBox Widget
- PyQt - QMenuBar, QMenu & Qaction Widgets
- PyQt - QToolTip
- PyQt - QInputDialog Widget
- PyQt - QFontDialog Widget
- PyQt - QDialog Widget
- PyQt - QFileDialog Widget
- PyQt - QTab Widget
- PyQt - QSplitter Widget
- PyQt - QDock Widget
- PyQt - QStatusBar Widget
- PyQt - QTabBar
- PyQt - QList Widget
- PyQt - QScrollBar Widget
- PyQt - QProgressBar
- PyQt - QCalendar Widget
- PyQt - QMessageBox Widget
- PyQt - QPlainTextEdit
- PyQt - QDateEdit
- PyQt - QDateTimeEdit
- PyQt - QTimeEdit
- PyQt - QTextEdit
- PyQt - QTextBrowser
- PyQt - QScrollArea
- PyQt - Drag and Drop
- PyQt - Multiple Document Interface
- PyQt - QDialog Class
- PyQt Views
- PyQt - QColumnView
- PyQt - QTableView
- PyQt Drawing API
- PyQt - Drawing API
- PyQt - Drawing a Line
- PyQt - Drawing a Rectangle
- PyQt - Drawing a Triangle
- PyQt - Drawing a Circle
- PyQt - Drawing a Ellipse
- PyQt - Drawing a Polygon
- PyQt - Geometric Transformation
- PyQt - Drawing Effect
- PyQt Groups
- PyQt - QButtonGroup
- PyQt - QGroupBox
- PyQt Effects
- PyQt - Effects
- PyQt - Opacity Effect
- PyQt - QGraphicsBlur Effect
- PyQt - QGraphicsColorize Effect
- PyQt - QGraphicsDropShadow Effect
- PyQt Events
- PyQt - Event Handling
- PyQt - Drag & Drop Events
- PyQt - File Open Event
- PyQt - Action Event
- PyQt - Hide Event
- PyQt - Resize Event
- PyQt Database
- PyQt - Database Handling
- PyQt Essentials
- PyQt - BrushStyle Constants
- PyQt - QClipboard
- PyQt - QPixmap Class
- PyQt Useful Resources
- PyQt - Quick Guide
- PyQt - Useful Resources
- PyQt - Discussion
PyQt - QFormLayout Class
QFormLayout is a convenient way to create two column form, where each row consists of an input field associated with a label. As a convention, the left column contains the label and the right column contains an input field.
Following is the three overloads of addRow() method addLayout() are commonly used.
Sr.No. | Methods & Description |
---|---|
1 |
addRow(QLabel, QWidget) Adds a row containing label and input field |
2 |
addRow(QLabel, QLayout) Adds a child layout in the second column |
3 |
addRow(QWidget) Adds a widget spanning both columns |
Text Container and Radio Button in PyQt
The method LineEdit() create a single-line text-entry widget container whereas QRadioButton() create the option selection. Here, below the program build GUI form using following components- widgets using QLabel(), radio button using QRadioButton(), and QPushButton() to create the clickable button.
Example
In this example, the program adds a LineEdit field to input name in the first row. Then it adds a vertical box layout for two address fields in the second column of the next row. Next, a horizontal box layout object containing two Radio button fields is added in the second column of the third row. The fourth row shows two buttons 'Submit' and 'Cancel'.
import sys from PyQt6.QtCore import * from PyQt6.QtGui import * from PyQt6.QtWidgets import * def window(): app = QApplication(sys.argv) win = QWidget() l1 = QLabel("Name") nm = QLineEdit() l2 = QLabel("Address") add1 = QLineEdit() add2 = QLineEdit() fbox = QFormLayout() fbox.addRow(l1, nm) vbox = QVBoxLayout() vbox.addWidget(add1) vbox.addWidget(add2) fbox.addRow(l2, vbox) # Create a button group for the radio buttons gender_group = QButtonGroup() r1 = QRadioButton("Male") r2 = QRadioButton("Female") # Add the radio buttons to the group gender_group.addButton(r1) gender_group.addButton(r2) hbox = QHBoxLayout() hbox.addWidget(r1) hbox.addWidget(r2) hbox.addStretch() fbox.addRow(QLabel("Sex"), hbox) fbox.addRow(QPushButton("Submit"), QPushButton("Cancel")) win.setLayout(fbox) win.setWindowTitle("PyQt") win.show() sys.exit(app.exec()) if __name__ == '__main__': window()
Output
The above code produces the following output −

Sign Up Form using QFormLayout class
Every website builds a sign-up form to store the data. It enables the user to register the form from multiple locations with the information. Here, we use the addrow() method to add the new label to sign-up page and display the result using show() method.
Example
In this example, we illustrate the sign up form using the class QFormLayout.
import sys from PyQt6.QtWidgets import QApplication, QWidget, QPushButton, QLineEdit, QFormLayout class MainWindow(QWidget): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setWindowTitle('Sign Up Form') layout = QFormLayout() self.setLayout(layout) layout.addRow('Enter the name:', QLineEdit(self)) layout.addRow('Enter the Email:', QLineEdit(self)) layout.addRow('Enter the Pincode:', QLineEdit(self, echoMode=QLineEdit.EchoMode.Password)) layout.addRow('Enter the Mobile Number:', QLineEdit(self)) layout.addRow(QPushButton('Sign Up Form')) # show the window self.show() if __name__ == '__main__': app = QApplication(sys.argv) window = MainWindow() sys.exit(app.exec())
Output
On executing the code, we get the result of sign up form in PyQt Window-
