@@ -478,16 +478,23 @@ def drawRectangle(self, rect):
478478 # Draw the zoom rectangle to the QPainter. _draw_rect_callback needs
479479 # to be called at the end of paintEvent.
480480 if rect is not None :
481+ x0 , y0 , w , h = [pt / self ._dpi_ratio for pt in rect ]
482+ x1 = x0 + w
483+ y1 = y0 + h
481484 def _draw_rect_callback (painter ):
482- scaled_rect = [pt / self ._dpi_ratio for pt in rect ]
483485 pen = QtGui .QPen (QtCore .Qt .black , 1 / self ._dpi_ratio )
484486 pen .setDashPattern ([3 , 3 ])
485- painter .setPen (pen )
486- painter .drawRect (* scaled_rect )
487- pen .setDashOffset (3 )
488- pen .setColor (QtCore .Qt .white )
489- painter .setPen (pen )
490- painter .drawRect (* scaled_rect )
487+ for color , offset in [
488+ (QtCore .Qt .black , 0 ), (QtCore .Qt .white , 3 )]:
489+ pen .setDashOffset (offset )
490+ pen .setColor (color )
491+ painter .setPen (pen )
492+ # Draw the lines from x0, y0 towards x1, y1 so that the
493+ # dashes don't "jump" when moving the zoom box.
494+ painter .drawLine (x0 , y0 , x0 , y1 )
495+ painter .drawLine (x0 , y0 , x1 , y0 )
496+ painter .drawLine (x0 , y1 , x1 , y1 )
497+ painter .drawLine (x1 , y0 , x1 , y1 )
491498 else :
492499 def _draw_rect_callback (painter ):
493500 return
0 commit comments