Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setItemWidget causing crash

I'm trying to add a QLabel to a QTreeWidgetItem but Python crashes on the setItemWidget call.

Any ideas why it crashes?

Here is the code:

from PySide import QtCore, QtGui

view = QtGui.QTreeWidget()
view.show()

newItem =  QtGui.QTreeWidgetItem(view)
view.setItemWidget(newItem,0,QtGui.QLabel('abc'))
like image 433
Chuck Carlson Avatar asked Dec 25 '14 04:12

Chuck Carlson


1 Answers

You need to keep a reference to the label, or give it a parent:

    view.setItemWidget(newItem, 0, QtGui.QLabel('abc', view))
like image 75
ekhumoro Avatar answered Oct 13 '22 20:10

ekhumoro