Hyun-geun Kim
Hyun-geun Kim

Reputation: 1069

pyqt : set Item Boundary Line with QStyledItemDelegate

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?

Upvotes: 0

Views: 470

Answers (1)

Eric Hulser
Eric Hulser

Reputation: 4022

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 ):

Upvotes: 1

Related Questions