PDA

View Full Version : Another delegate problem...



alexandernst
8th August 2009, 18:47
I made (with numbat's help) a delegate for drawing items in a qtreeview. But now I have another problem with the delegate.

http://img19.imageshack.us/img19/9328/delegate1.jpg

Do you see the border line (1px) that is a little bit darker than the color around it? It should be drawn at the very left part of the item. Instead of that the delegate draws the item (at the right) and some kind of square (at the left).

And if I set border-radius (rounded borders) in the stylesheet, I get rounded borders on the item and on the square.

How can I make it draw everything as just one item?

Delegate code:



def paint(self, painter, option, index):
if not index.isValid():
return
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)
painter.translate(options.rect.left(), options.rect.top())
rect = QRectF(0, 0, options.rect.width(), options.rect.height())
doc.drawContents(painter, rect)
painter.restore()


Thanks

alexandernst
9th August 2009, 03:18
Thinking about it better, it would be better if I could remove that strange square.
Does somebody know how to remove it?

alexandernst
9th August 2009, 15:04
I solved it. It's because of the branch's. If somebody is having the same problem, here is the stylesheet that will remove the square:



QTreeView::branch {
background: white;
}

QTreeView::branch:has-siblings:!adjoins-item {
background: white;
border-image: none;
image: none;
}

QTreeView::branch:has-siblings:adjoins-item {
background: white;
border-image: none;
image: none;
}

QTreeView::branch:!has-children:!has-siblings:adjoins-item {
background: white;
border-image: none;
image: none;
}


QTreeView::branch:has-children:!has-siblings:closed,
QTreeView::branch:closed:has-children:has-siblings {
background: white;
border-image: none;
}

QTreeView::branch:open:has-children:!has-siblings,
QTreeView::branch:open:has-children:has-siblings {
background: white;
border-image: none;
}

Lykurg
9th August 2009, 15:14
You also could check the index inside your paint method if it is a branch and then remove the QStyle::State_Selected from the option.