[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Problem with resizing rubberband
From:       Lukas Hetzenecker <LuHe () gmx ! at>
Date:       2009-07-30 17:35:52
Message-ID: 200907301935.52809.LuHe () gmx ! at
[Download RAW message or body]

Just got this mail:

----------  Forwarded message  ----------

Subject: Re: [PyQt] Problem with resizing rubberband
Date: Donnerstag 30 Juli 2009
From: Shriramana Sharma <samjnaa@gmail.com>
To: Lukas Hetzenecker <LuHe@gmx.at>

Hello. I have attached my rubberband label class which solves the 
problem. I trust that you will be able to understand from the code how I 
have solved the problem (it is by manually setting all the coords of the 
rubberband geometry without using setRight etc).

Since I am no longer a member of the pyqt mailing list (and don't want 
to subscribe for just this) can you please forward this to the list so 
that anyone else can be benefited.

Shriramana Sharma.

-------------------------------------------------------------

Am Donnerstag 30 Juli 2009 17:44:34 schrieb Lukas Hetzenecker:
> Hello,
>
> could anybody solve this issue?
> I ran into a similar issue when I tried to use QRubberBand to select an
> area of a QImage - are there any useful examples for this?
>
> Thanks,
> Lukas
>
> Am Freitag 08 Mai 2009 11:45:53 schrieb Shriramana Sharma:
> > Hello. I previously reported a problem with drawing a rubberband and a
> > workaround was provided. I now find that I am unable to resize a
> > rubberband using a QRect which has been modified using setLeft etc.
> > Please see the attached files. The C++ version works whereas the Python
> > version does not.


["rubberbandlabel.py" (text/x-python)]

class rubberBandLabel ( QLabel ) :
	def __init__ ( self, parent = None ) :
		QLabel . __init__ ( self, parent )

		self . rubberBand = QRubberBand ( QRubberBand . Rectangle, self )
		self . rubberBand . setGeometry ( QRect () )
		self . rubberBand . show ()

		self . rubberBandWindowGeo = QRect ()
		self . center = QPoint ()
		self . tweakingRubberBand = False
		self . rbx = self . rby = self . rbw = self . rbh = 0

	def mousePressEvent ( self, event ) :
		pt = self . mapFromGlobal ( event . globalPos () )

		if self . hasRubberBand () :
			rg = self . rubberBand . geometry ()
			tl, tr, bl, br = rg . topLeft (), rg . topRight (), rg . bottomLeft (), rg . \
bottomRight ()  s = 5
			off, offx, offy = QPoint ( s, s ), QPoint ( s + 1, -s ), QPoint ( -s, s + 1 )

			boxes = {
				( "topLeft"     , Qt . SizeFDiagCursor ) : QRect ( tl - off , tl + off  ),
				( "topRight"    , Qt . SizeBDiagCursor ) : QRect ( tr - off , tr + off  ),
				( "bottomLeft"  , Qt . SizeBDiagCursor ) : QRect ( bl - off , bl + off  ),
				( "bottomRight" , Qt . SizeFDiagCursor ) : QRect ( br - off , br + off  ),
				( "top"         , Qt . SizeVerCursor   ) : QRect ( tl + offx, tr - offx ),
				( "bottom"      , Qt . SizeVerCursor   ) : QRect ( bl + offx, br - offx ),
				( "left"        , Qt . SizeHorCursor   ) : QRect ( tl + offy, bl - offy ),
				( "right"       , Qt . SizeHorCursor   ) : QRect ( tr + offy, br - offy )
				}

			for k, v in boxes . iteritems () :
				if v . contains ( pt ) :
					self . rbx1, self . rby1, self . rbx2, self . rby2 = rg . x (), rg . y (), rg . \
x () + rg . width (), rg . y () + rg . height ()  self . tweakingPart = k [ 0 ]
					self . setCursor ( k [ 1 ] )
					self . tweakingRubberBand = True
					return

		self . rbOrigin = pt
		self . rubberBand . setGeometry ( QRect ( self . rbOrigin, QSize () ) )

	def mouseMoveEvent ( self, event ) :
		pt = self . mapFromGlobal ( event . globalPos () )
		if self . tweakingRubberBand :
			tp = self . tweakingPart
			if   tp == "topLeft"     : self . rbx1, self . rby1 = pt . x (), pt . y ()
			elif tp == "topRight"    : self . rbx2, self . rby1 = pt . x (), pt . y ()
			elif tp == "bottomLeft"  : self . rbx1, self . rby2 = pt . x (), pt . y ()
			elif tp == "bottomRight" : self . rbx2, self . rby2 = pt . x (), pt . y ()
			elif tp == "top"         : self . rby1 = pt . y ()
			elif tp == "bottom"      : self . rby2 = pt . y ()
			elif tp == "left"        : self . rbx1 = pt . x ()
			elif tp == "right"       : self . rbx2 = pt . x ()
			self . rubberBand . setGeometry ( self . rbx1, self . rby1, self . rbx2 - self . \
rbx1, self . rby2 - self . rby1 )  else :
			self . rubberBand . setGeometry ( QRect ( self . rbOrigin, pt ) . normalized () )

	def mouseReleaseEvent ( self, event ) :
		self . tweakingPart = ""
		self . tweakingRubberBand = False
		self . unsetCursor ()
		if self . hasRubberBand () :
			self . correctRubberBand ()
			self . emit ( SIGNAL ( "rubberBandCreated ()" ) )
		else :
			self . emit ( SIGNAL ( "rubberBandDestroyed ()" ) )

	def hasRubberBand ( self ) :
		return self . rubberBand . geometry () . isValid ()

	def correctRubberBand ( self ) :
		rubberInLabelGlobalGeo = toGlobal ( self . rubberBand . geometry (), self ) & \
toGlobal ( self . geometry (), self . parent () )  self . rubberBandWindowGeo = \
fromGlobal ( rubberInLabelGlobalGeo, self . parent () ) # self . parent () == form  \
self . rubberBand . setGeometry ( fromGlobal ( rubberInLabelGlobalGeo , self ) )  \
return rubberInLabelGlobalGeo

	def restoreRubberBand ( self ) :
		self . rubberBand . setGeometry ( fromWindow ( self . rubberBandWindowGeo, self, \
self . parent () ) )

	def removeRubberBand ( self ) :
		self . rubberBand . setGeometry ( QRect () )
		self . emit ( SIGNAL ( "rubberBandDestroyed ()" ) )



_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic