Is there a way to a way to lock the aspect for pyqtgraph ROI ScaleRotateHandle?

Sorin Tatah sorin at lightoptech.com
Sun May 16 01:13:10 BST 2021


Hi,


I'm using pyqtgraph ViewBox to process images with the ImageItem class and I use the ROI class to mark important part of the image. The images I'm processing requires me to use the setAspectLocked on the ViewBox with a given x and y for the ratio.

The problem is that if I set the aspect lock on the ViewBox, the ROI scale rotate handle becomes stretched if rotated. Is there a way to lock it? Or is there a way to only apply setAspectLocked on the ImageItem class and not the entire ViewBox so as to not affect other widgets?


There is a modified sample code bellow with my issue. Try rotating the rectangle on the right.


`# -*- coding: utf-8 -*-
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np

pg.setConfigOptions(imageAxisOrder='row-major')


## create GUI
app = QtGui.QApplication([])
w = pg.GraphicsLayoutWidget(show=True, size=(1000,800), border=True)
w.setWindowTitle('pyqtgraph example: ROI Examples')

w3 = w.addLayout(row=1, col=0)
v3 = w3.addViewBox(row=1, col=0)
v3.setAspectLocked(True,1.8/18)

r3a = pg.ROI([0,0], [10,10])
v3.addItem(r3a)
## handles scaling horizontally around center
r3a.addScaleHandle([1, 0.5], [0.5, 0.5])
r3a.addScaleHandle([0, 0.5], [0.5, 0.5])

## handles scaling vertically from opposite edge
r3a.addScaleHandle([0.5, 0], [0.5, 1])
r3a.addScaleHandle([0.5, 1], [0.5, 0])

## handles scaling both vertically and horizontally
r3a.addScaleHandle([1, 1], [0, 0])
r3a.addScaleHandle([0, 0], [1, 1])

r3b = pg.ROI([20,0], [10,10])
v3.addItem(r3b)
## handles rotating around center
r3b.addRotateHandle([1, 1], [0.5, 0.5])
r3b.addRotateHandle([0, 0], [0.5, 0.5])

## handles rotating around opposite corner
r3b.addRotateHandle([1, 0], [0, 1])
r3b.addRotateHandle([0, 1], [1, 0])

## handles rotating/scaling around center
r3b.addScaleRotateHandle([0, 0.5], [0.5, 0.5])
r3b.addScaleRotateHandle([1, 0.5], [0.5, 0.5])

v3.disableAutoRange('xy')
v3.autoRange()

if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()`
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20210515/c84c1a43/attachment-0001.htm>


More information about the PyQt mailing list