def viewportEvent(self, e):
        if e.type() == QEvent.TouchBegin or e.type() == QEvent.TouchUpdate or 
e.type() == QEvent.TouchEnd:
            points = e.touchPoints()
            if e.type() == QEvent.TouchBegin and not self.scene().dragItem:
                e.accept()
            if len(points) == 2 and e.type() == QEvent.TouchUpdate:
                e.accept()
                THRESHOLD = 10.0
                COEFF = 1.0
                orig = QLineF(points[0].startPos(), points[1].startPos())
                now = QLineF(points[0].pos(), points[1].pos())
                delta = abs(now.length() - orig.length())
                if self.zoomScaleStart is None and delta > THRESHOLD:
                    self.zoomScaleStart = self.scene().scaleFactor
                if self.zoomScaleStart:
                    if self.animTimer is None:
                        self.animTimer = self.startTimer(util.ANIM_TIMER_MS)
                    zoom = self.zoomScaleStart * (now.length() / orig.length()) 
* COEFF
                    self.zoomAbsolute(zoom)

                    # oldVValue = self.verticalScrollBar().value()              
                                                  
                    # vDiff = points[0].lastPos().y() - points[0].pos().y()     
                                                  
                    # newVValue = oldVValue + vDiff                             
                                                  
                    # self.verticalScrollBar().setValue(newVValue)              
                                                  

                    # oldHValue = self.horizontalScrollBar().value()            
                                                  
                    # hDiff = points[0].lastPos().x() - points[0].pos().x()     
                                                  
                    # newHValue = oldHValue + hDiffOA                           
                                                  
                    # self.horizontalScrollBar().setValue(newHValue)            
                                                  

            if e.type() == QEvent.TouchEnd or e.type() == QEvent.TouchCancel:
                self.zoomScaleStart = None
                if self.animTimer:
                    self.killTimer(self.animTimer)
                    self.animTimer = None
            return True
        return super().viewportEvent(e)

    def zoomAbsolute(self, x):
        if x < 0:
            x = .0000001
        if self.scene().scaleFactor != x:
            self.scene().setScaleFactor(x)
        self.scaleWaiting = True

    def _setScale(self, x):
        self.setTransform(QTransform.fromScale(x, x))

    def timerEvent(self, e):
        if self.scaleWaiting:
            x = self.scene().scaleFactor
            self._setScale(x)
            self.scaleWaiting = False
        if self.panWaiting:
            self.centerOn(self.panCenter)
            self.panWaiting = False


> On Jul 25, 2017, at 12:27 AM, Christian Gagneraud <[email protected]> wrote:
> 
> 
> 
> On 25/07/2017 7:24 pm, "Patrick Stinson" <[email protected] 
> <mailto:[email protected]>> wrote:
> Hi there!
> 
> If I am setting a QGraphicsView's scale via setTransform() while scrolling 
> up/down+left/right with two fingers on the trackpad, but the paint updates 
> don’t come until after I stop moving my fingers which stops the wheel events. 
> Is there a way to update the view with the new transform while scrolling
> 
> Can you show your event handlers, difficult to say without seeing except that 
> it should work.
> 
> Chris
> 
> 
> 
> Thanks!
> _______________________________________________
> Interest mailing list
> [email protected] <mailto:[email protected]>
> http://lists.qt-project.org/mailman/listinfo/interest 
> <http://lists.qt-project.org/mailman/listinfo/interest>
> 
> 

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to