I’m trying to change the size of my grid whenever I add a new row and keep the sizes of the prev rows, but the rows keep getting slightly squished vertically. How can I fix this?
GUI
class MyForm(Ui_Form):
def __init__(self, parent=None):
super().__init__()
self.setupUi(parent)
self.gridLayoutWidget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.gridLayoutWidget.setLayout(self.gridLayout)
self.pushButton.clicked.connect(self.addNewRow)
def addNewRow(self):
new_line = QLineEdit("New Course")
new_line.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
g_widget = self.gridLayoutWidget
row_count = self.gridLayout.rowCount()
self.gridLayout.addWidget(new_line, row_count, 0)
self.gridLayoutWidget.resize(g_widget.width(), g_widget.height() + new_line.sizeHint().height())
def addNewColumn(self):
newLine = QLineEdit("New Course ID")
colCount = self.gridLayout.columnCount()
self.gridLayout.addWidget(newLine, 0, colCount)
I used .resize() to keep it from getting squished vertically, and it made the squishing slightly less but it didn’t solve the full problem.
New contributor
Bilguun Chuluun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.