我试图调整一些pyqtgraph.AxisItem对象的宽度,并且在创建时我尝试设置preferredWidth,以便稍后再调用它,它没有回忆起我之前设置的值。最终我发现我试图设定的价值似乎根本没被接受。
我注意到这种行为不仅与preferredSizes有关,而且还有MinimumSizes
以下是我可以生成的用于复制问题的最基本代码:
import pyqtgraph as pg
import sys
from pyqtgraph.Qt import QtGui, QtCore
class plotWidget(pg.GraphicsView):
def __init__(self):
super().__init__()
self.layout = pg.GraphicsLayout()
self.setCentralWidget(self.layout)
self.main_plot = pg.PlotItem()
ax = self.main_plot.getAxis('left')
new_min_width = 100
ax.setMinimumWidth(new_min_width)
self.layout.addItem(self.main_plot)
# assert test will fail
assert ax.minimumWidth() == new_min_width
if __name__ == '__main__':
pg.mkQApp()
win = plotWidget()
win.show()
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
任何建议都将不胜感激。