PDA

View Full Version : QTreeView and itemDelegate code



alexandernst
21st April 2010, 21:29
This code worked just fine some months ago (maybe half year), and now it's not working. Why could it be? Message error is ''NoneType' object has no attribute 'style'' from line 12.



def paint(self, painter, option, index):
if not index.isValid():
return
painter.translate(0, 0)
options = QStyleOptionViewItemV4(option)
self.initStyleOption(options, index)
painter.save()
painter.setRenderHint(QPainter.Antialiasing, True)
doc = QTextDocument()
doc.setHtml(options.text)
options.text = ""
options.widget.style().drawControl(QStyle.CE_ItemV iewItem, options, painter, options.widget) #<---ERROR
painter.translate(options.rect.left() + self.sizeDp(index) + 3, options.rect.top()) #paint text right after the dp + 3pixels
rect = QRectF(0, 0, options.rect.width(), options.rect.height())
doc.drawContents(painter, rect)
painter.restore()


Why could this be happening?

alexandernst
22nd April 2010, 18:00
the solution was

options.widget.style().drawControl(QStyle.CE_ItemV iewItem, options, painter, options.widget) #<---ERROR

QApplication.style().drawControl(QStyle.CE_ItemVie wItem, options, painter, options.widget)