[PyQt] item selection in a graphicsscene

Martin Airs camberwell at gmail.com
Fri Sep 14 22:28:17 BST 2012


good day all,

I'm currently writing a Plasmoid for KDE, so I'm not 100% certain who's lap to 
lay this in, but I'll try here first.

I'm using a Plasma.Frame which inherits a QGraphicsWidget, in my subclass I 
have reimplemented the itemChange function so I can set the element prefix of 
the SVG used to paint the frame.

when i press each item with the left mouse button, everything works as 
expected :)
however if i right click an item, its ElementPrefix changes ok and the menu 
pops up, but the other item that is selected doesn't deselect. and i end up 
with 2 selected items until i click one again.

Martin

here is a snippet of the code...

    def itemChange(self, change, value):
        if change == QGraphicsItem.ItemSelectedChange:
            print "selection changed"
            if value == QVariant(True):
               self.border.setElementPrefix("selected")
            else:
               self.border.setElementPrefix("normal")
            self.update()
        return value

    def mousePressEvent(self, event):
        if event.button() == 1:
            self.setSelected(1)
            self.update()
        if event.button() == 2:
            self.setSelected(1)
            self.update()
            self.menu.exec_(QCursor.pos())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20120914/9fbbe7d1/attachment.pgp>


More information about the PyQt mailing list