0
由於我沒有得到this問題的答案,我試着用PyQt解決它。 顯然,當涉及到QScrollArea時,並不那麼容易......用PyQt和matplotlib在可滾動窗口小部件中顯示幾個圖
我寫了一個小測試,基本上做我在找的東西,但它沒有顯示滾動區域和裏面的情節,因爲我期望:
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_())
任何人都可以解釋爲什麼它不工作?
太棒了!這比我提出的修復要好得多。 –