[PyQt] QFormLayout drops the label text when using setItem

MaFeng mengjue at outlook.com
Thu Jun 4 16:41:27 BST 2015


Hello everyone,
I got one very strange issue about QFormLayout, and I put this question in stackoverflow.com (http://stackoverflow.com/questions/30634370/qformlayout-drops-the-label-text-when-using-setitem) and not got any comment yet. So I post them here and am not sure whether it is a PyQt bug.
Using below code to add Items into QFormLayout, but nothing displayed and yet no any error logs can be found.fl1 = QFormLayout()
label = QLabel()
label.setText("HELLO")
item1 = QWidgetItem(label)
fl1.setItem(1, 0, item1)
item2 = QWidgetItem(QLineEdit())
fl1.setItem(1, 1, item2)
fl1.update()
fl1.invalidate()Per the pyqt doc, I didn't yet find any specific note about setItem:QFormLayout.setItem (self, int row, ItemRole role, QLayoutItem item)The item argument has it's ownership transferred to Qt.Sets the item in the given row for the given role to item, extending the layout with empty rows if necessary.If the cell is already occupied, the item is not inserted and an error message is sent to the console. The item spans both columns.Warning: Do not use this function to add child layouts or child widget items. Use setLayout() or setWidget() instead.See also setLayout().
I understood that I can use addRow to add items into QFormLayout. I just want to know what happened in background and how to resolve them under this condition.
Thanks you!
Meng Jue 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150604/03aa9492/attachment.html>


More information about the PyQt mailing list