python - 有没有办法锁定 pyqtgraph ROI ScaleRotateHandle 的方面?
问题描述
我正在使用 pyqtgraph ViewBox 来处理带有 ImageItem 类的图像,并使用 ROI 类来标记图像的重要部分。我正在处理的图像要求我使用具有给定 x 和 y 像素大小的 setAspectLocked。
问题是,如果我在 ViewBox 上设置纵横比锁定,则 ROI 比例旋转手柄在旋转时会被拉伸。有没有办法锁定它?或者有没有办法只在 ImageItem 类而不是整个 ViewBox 上应用 setAspectLocked?
我的问题有一个修改后的示例代码。尝试旋转右侧的矩形。
# -*- 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_()
解决方案
推荐阅读
- python - python 从同一文件夹导入模块,但从父级调用
- r - 从嵌套列表中提取多列(使用对象前缀)
- ssh - 成功登录后,ssh 连接在挂起和响应之间循环
- python - Python replace() - 如何避免重复replace()?
- linux - 更改文件中多个文件路径的文件权限
- javascript - 计数器但按特定数字
- sql-server - 使用 SQL 将子 XML 提取到(子元素的)列表中
- javascript - 如何合并子数组中的对象,以便在javascript中留下一个数组和多个对象
- docker - Docker仪表板未打开
- java - jackson-databind Objectmapper 2.12.2 的最佳性能策略