To add several widgets for each new entry in PyQt6, create one QGridLayout for the containing widget, then place each entry’s widgets in the same columns and a new row using addWidget(widget, row, column). For example, an image list can put its filename, width, and height in columns 0, 1, and 2. Keep the layout and row-to-widget references on the object that manages the entries so later updates and removals stay manageable.
Set up a persistent grid
A QGridLayout assigns widgets to cells by row and column. Its top-left cell is (0, 0); the grid grows as items are added. Install it on the widget that contains the entries, or add it to a parent layout if the grid is only one part of a larger interface. Qt’s layout system positions child widgets, responds to resizing, and updates when contents change. See the QGridLayout reference and Qt Layout Management.
As an Amazon Associate I earn from qualifying purchases.
from PyQt6.QtWidgets import QGridLayout, QWidget
class EntryList(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.grid = QGridLayout(self)
self.next_row = 0
self.widgets_by_row = {}
Constructing the layout with the containing widget installs it as that widget’s layout. If a grid must sit inside another layout, create it without a parent and insert it into the parent layout instead.
Add each entry in stable columns
For every new entry, create its widgets, add them at the current row, and then increment the row index. The column positions stay consistent across entries, so each field type lines up vertically.
#1 Best Overall
def add_image_entry(self, filename, width, height):
row = self.next_row
fields = [
QLineEdit(filename),
QLineEdit(str(width)),
QLineEdit(str(height)),
]
for column, widget in enumerate(fields):
self.grid.addWidget(widget, row, column)
self.widgets_by_row[row] = fields
self.next_row += 1
This example treats each selected image as one logical entry with filename, width, and height fields, matching the three-column pattern in the PyQt6 layouts tutorial. In an application, use the appropriate widget types for the data and retain references to them if you will read, update, hide, or remove them later.
The row number is an interface coordinate, not the entry’s identity. If entries can be reordered or deleted, keep a mapping from your application’s stable entry ID to its widgets; do not assume a row index remains a permanent identifier.
Rank #2
Control column widths and spanning
Grid columns are not automatically equal in size. Set column stretch factors when extra horizontal space should be divided unevenly. A larger relative factor assigns that column a larger share of the available extra width:
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →self.grid.setColumnStretch(0, 3)
self.grid.setColumnStretch(1, 1)
self.grid.setColumnStretch(2, 1)
These factors influence how extra space is distributed; they do not override a widget’s size hint, size policy, or minimum size. If a field needs more than one grid cell, addWidget also accepts row and column spans, for example self.grid.addWidget(widget, row, 0, 1, 3) to span one row across three columns. Check the QGridLayout API for the full method signatures and grid inspection methods, including rowCount(), columnCount(), and itemAtPosition().
Rank #3
Remove or hide an entry’s widgets
Qt provides removeWidget(widget) to remove a widget from layout management. Hiding a widget also excludes it from layout participation until it is shown again. Neither action by itself is a complete row-deletion operation: keep references to the widgets for each logical entry, then act on every widget in that entry.
def remove_entry(self, row):
fields = self.widgets_by_row.pop(row, [])
for widget in fields:
self.grid.removeWidget(widget)
widget.deleteLater()
Removing a widget from the layout does not delete the widget, which is why the example schedules each for deletion. If rows may be removed and then new ones appended, a simple increasing row counter can leave gaps; either compact and reposition the remaining entries, or derive coordinates from an ordered collection of active entries.
For interfaces with complex per-entry behavior or frequent row-level updates, consider placing each entry’s fields inside its own custom row widget and adding that single widget to a vertical layout. That groups ownership and cleanup more directly than managing many independent grid items.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Choose QGridLayout or QFormLayout
Use QGridLayout when each entry has several stable fields, explicit coordinates, cells that span multiple rows or columns, or column-specific stretch behavior. For a conventional label-and-input form, QFormLayout is designed to pair labels with input widgets and may express the structure more clearly. Qt documents both choices in its layout management overview.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




