I have this code:
myEdit = QLineEdit()
myQFormLayout.addRow("myLabelText", myEdit)
Now I have to remove the row by reference to myEdit
only:
myQformLayout.removeRow(myEdit)
But there is no API for that. I can use .takeAt()
, but how can I get the argument? How do I find the label index, or the index of myEdit
?
You can just schedule the widget and its label (if it has one) for deletion, and let the form adjust itself accordingly. The label for the widget can be retrieved using labelForField.
Python Qt code:
label = myQformLayout.labelForField(myEdit)
if label is not None:
label.deleteLater()
myEdit.deleteLater()
my solution...
in header file:
QPointer<QFormLayout> propertiesLayout;
in cpp file:
// Remove existing info before re-populating.
while ( propertiesLayout->count() != 0) // Check this first as warning issued if no items when calling takeAt(0).
{
QLayoutItem *forDeletion = propertiesLayout->takeAt(0);
delete forDeletion->widget();
delete forDeletion;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With