[PyKDE] QPoint arithmetric operator problems

bdw bdw_box at yahoo.co.uk
Thu Feb 3 19:15:18 GMT 2005


On Thu, 3 Feb 2005 17:02 Hans-Peter Jansen <hpj at urpla.net> wrote: 
> Hi,
> 
> next problem: while substraction or addition of two QPoints should 
> work, it won't, at least not with
> sip version: 4.1.1
> Qt version: 3.2.1
> PyQt version: 3.13
> 
> Any ideas?
> 
> Cheers,
> Pete
> > #!/usr/bin/env python
> # -*- coding: utf-8 -*-
> 
> import sys
> from qt import *
> 
> class eventTest(QPushButton):
>     def __init__(self, *args):
>         QPushButton.__init__(self, "Drag me!", *args)
>         self.pressPos = None
> 
>     def mousePressEvent(self, e):
>         self.pressPos = p = e.pos()

Hello Peter

I think a copy of the QPoint needs to be cached here, otherwise the
mousemove handler will always be adding the same QPoint to itself.

Replacing the line above with the following seems to work okay for me.

	self.pressPos = p = QPoint(e.pos())

Hope this helps,
bdw

>         print "mousePressEvent:", p.x(), p.y()
> 
>     def mouseMoveEvent(self, e):
>         if self.pressPos:
>             p = e.pos()
>             print "mouseMoveEvent pos:", p.x(), p.y()
>             p = self.pressPos - p
>             print "Dist:", p.x(), p.y(), p.manhattanLength()
>             p = self.pressPos
>             p -= e.pos()
>             print "Dist:", p.x(), p.y(), p.manhattanLength()
>             p = self.pressPos + p
>             print "Add:", p.x(), p.y(), p.manhattanLength()
>         else:
>             print "mouseMoveEvent ignored"
> 
>     def mouseReleaseEvent(self, e):
>         print "mouseReleaseEvent"
>         self.pressPos = None
> 
> 
> if __name__ == "__main__":
>     app = QApplication(sys.argv)
>     win = eventTest(None)
>     app.setMainWidget(win)
>     win.show()
>     ret = app.exec_loop()
>     sys.exit(ret)
> > _______________________________________________
> PyKDE mailing list    PyKDE at mats.imk.fraunhofer.de
> http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
>  


	
	
		
___________________________________________________________ 
ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com




More information about the PyQt mailing list