由于我没有得到这个问题的答案,我尝试用 PyQt 解决它。显然,当涉及到 QScrollArea 时,这并不容易......
我写了一个小测试,基本上可以满足我的要求,但它没有像我预期的那样显示滚动区域和其中的图:
from PyQt4 import QtCore, QtGui
import os,sys
#import matplotlib
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
from matplotlib.figure import Figure
qapp = QtGui.QApplication(sys.argv)
qwidget = QtGui.QWidget()
qwidget.setGeometry(QtCore.QRect(0, 0, 500, 500))
qlayout = QtGui.QHBoxLayout(qwidget)
qwidget.setLayout(qlayout)
qscroll = QtGui.QScrollArea(qwidget)
qscroll.setGeometry(QtCore.QRect(0, 0, 500, 500))
qscroll.setFrameStyle(QtGui.QFrame.NoFrame)
qlayout.addWidget(qscroll)
qscrollContents = QtGui.QWidget()
qscrollLayout = QtGui.QVBoxLayout(qscrollContents)
qscrollLayout.setGeometry(QtCore.QRect(0, 0, 1000, 1000))
qscroll.setWidget(qscrollContents)
qscroll.setWidgetResizable(True)
for i in xrange(5):
qfigWidget = QtGui.QWidget(qscrollContents)
fig = Figure((5.0, 4.0), dpi=100)
canvas = FigureCanvas(fig)
canvas.setParent(qfigWidget)
toolbar = NavigationToolbar(canvas, qfigWidget)
axes = fig.add_subplot(111)
axes.plot([1,2,3,4])
qscrollLayout.addWidget(qfigWidget)
qscrollContents.setLayout(qscrollLayout)
qwidget.show()
exit(qapp.exec_())
谁能解释为什么它不起作用?