📅  最后修改于: 2023-12-03 15:18:50.739000             🧑  作者: Mango
PyQtGraph是用于科学数据概览和2D / 3D数据可视化的Python库。它提供了针对科学和工程应用的高性能、交互式图形和图像视图。
在PyQtGraph中,可以通过以下方式轻松获取图像视图的帧大小:
from PyQt5 import QtGui, QtCore
import pyqtgraph as pg
app = QtGui.QApplication([])
win = pg.GraphicsLayoutWidget()
pg.setConfigOptions(antialias=True)
view = win.addViewBox()
img = pg.ImageItem(border='w')
view.addItem(img)
view.setRange(QtCore.QRectF(0, 0, 10, 10))
size = view.sceneBoundingRect().size()
print(size.width(), size.height())
from PyQt5 import QtGui, QtCore
import pyqtgraph as pg
app = QtGui.QApplication([])
win = pg.GraphicsLayoutWidget()
pg.setConfigOptions(antialias=True)
view = win.addViewBox()
img = pg.ImageItem(border='w')
view.addItem(img)
view.setRange(QtCore.QRectF(0, 0, 10, 10))
size = view.viewRect().size()
print(size.width(), size.height())
from PyQt5 import QtGui, QtCore
import pyqtgraph as pg
class MyViewBox(pg.ViewBox):
def sizeHint(self, which, constraint):
return QtCore.QSizeF(300, 300)
app = QtGui.QApplication([])
win = pg.GraphicsLayoutWidget()
pg.setConfigOptions(antialias=True)
view = MyViewBox()
img = pg.ImageItem(border='w')
view.addItem(img)
view.setRange(QtCore.QRectF(0, 0, 10, 10))
size = view.sizeHint(QtCore.Qt.PreferredSize, QtCore.QSizeF(300, 300)).toSize()
print(size.width(), size.height())
使用上述方法可以方便地获取图像视图的帧大小。
注意:在ViewBox视图上添加了obj之后,才能获取正确的帧大小。
以上是获取PyQtGraph图像视图帧大小的介绍。