PDA

View Full Version : pyqt custom QItemDelegate problem



spohle
31st January 2009, 02:48
i hope it's ok to ask pyqt questions here :eek:

in my paint method for my delegate i do this:


text = index.model().data(index).toString()
palette = QtGui.QApplication.palette()
txtEdit = QtGui.QTextDocument()
txtEdit.clear()
txtOption = QtGui.QTextOption()
txtOption.setWrapMode(QtGui.QTextOption.NoWrap)
txtEdit.setDefaultTextOption(txtOption)
txtEdit.setDefaultFont(option.font)
if option.state & QtGui.QStyle.State_Selected:
txtEdit.setHtml(QtCore.QString(text))
else:
txtEdit.setHtml(text)
txtEdit.setPageSize(QtCore.QSizeF(option.rect.size ()))

if option.state & QtGui.QStyle.State_Selected:
# selected state color
color = palette.highlight().color()
print color.red(), color.green(), color.blue()
else:
# normal state color
# find the current backgroundColor
color = QtGui.QColor(index.model().data(index, QtCore.Qt.BackgroundColorRole))
print "not selected"
print color.red(), color.green(), color.blue()

so i basicly create a textDocument widget. when i startet small and just put in the text when i saw the text items overlapping each other when i resize columns. so i came at the end to the code above which draws a rectangle with a color. now, my tree is set with alternating colors. so i can't just use one fixed color and need to figure out the background color of the current line where im in. i can't find a way to get the current background color from my delegate.

anyone knows the answer to this or maybe to even avoid drawing the rectangle all together and avoid the overlapping text ?

thanks in advance