[PyQt] QGraphicsView rubberband selection

Alexander Borghgraef alexander.borghgraef.rma at gmail.com
Fri Oct 30 10:44:31 GMT 2009


On Fri, Oct 30, 2009 at 9:44 AM, Antonio Valentino <
antonio.valentino at tiscali.it> wrote:

>
> I have the same problem. At the moment I have a solution based on
> event filters but I'm very interested in a solution exploiting built-in
> features so please keep updated.
>

Interesting to see that I'm not alone in this :-) I tried looking into event
filters, but I don't grasp how they work yet. I tried the following code to
capture the selection position, but it doesn't behave like I expected, maybe
you can shed some light on this?

class Dialog(QWidget):
>   def __init__(self, parent=None):
>     QWidget.__init__(self, parent)
>     self.gs = QGraphicsScene()
>     self.gv = QGraphicsView(self.gs)
>     self.gv.installEventFilter(self)
>     self.gv.show()
>
>   def eventFilter(self, object, event):
>     if event.type() == QEvent.MouseButtonPress:
>       self.p0 = self.mapFromGlobal(event.globalPos())

      return True
>     elif event.type() == QEvent.MouseButtonRelease:
>       self.p1 = self.mapFromGlobal(event.globalPos())
>       return True
>     else:
>       return False
>

So I attach the eventfilter to the QGraphicsView instance, and capture the
position at the mouse button press and release. When I print p0 and p1, only
p0 (the button press one) responds, the release does nothing. Any ideas why?

For the other readers, I'm still interested in how to get to the
QGraphicsView's rubberband selection data, as I think that would be the most
elegant solution.

-- 
Alex Borghgraef
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20091030/7b3c6d3e/attachment.html


More information about the PyQt mailing list