Question

I try to set Item Boundary Line in QListView.
When the mouse over the item, the line shows up and when the mouse leave the item, the line back to normal. That's the what I want.
So, I use QStyledItemDelegate and it seems do that, it is not proper.

class PixmapItemDelegate(QtGui.QStyledItemDelegate):    
    def paint(self, painter, option, index):        
        painter.save()

        if (option.state & QtGui.QStyle.State_MouseOver):            
            pen = QtGui.QPen(QtCore.Qt.yellow)            
        else:
            pen = QtGui.QPen(QtCore.Qt.transparent)
        pen.setWidth(2)
        painter.setPen(pen)
        painter.setBrush(QtGui.QBrush(QtCore.Qt.transparent))
        painter.drawRect(option.rect)

        painter.restore()

        super(PixmapItemDelegate, self).paint(painter, option, index)

The code is above.
If I select the item, it screwed up.
Selected item has a boundary and doesn't disappear.

How can I fix it?

Was it helpful?

Solution

Try making sure that the item state does not have selected as well:

if ( option.state & QtGui.QStyle.State_MouseOver and \
    not option.state & QtGui.QStyle.State_Selected ):
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top