PyQt4 + matplotlib in a QScrollWidget

不想你离开。 提交于 2019-12-02 04:46:30

Two steps to sketch an idea to solve this:

Unset the resizing of the ScollArea to display scroll bars. Change the line:

self.canvas.setWidgetResizable(True)

to

self.canvas.setWidgetResizable(False)

Then when adding a subplot change the figure height, because the canvas will determine it's height by checking the size of the figure:

def add_subplot(self, data=[]):
    rows = len(self.figure.axes) + 1
    for index, axes in enumerate(self.figure.axes, start=1):
        axes.change_geometry(rows, 1, index)

    ax = self.figure.add_subplot(rows, 1, index+1)
    ax.plot(data)
    self.figure.set_figheight(self.figure.get_figheight()*1.25)
    self.draw()

In the Main you have to let PySide know, that the it has to resize the widget in the scroll area:

    for x in range(5):
        self.canvas.widget().add_subplot()
        self.canvas.widget().adjustSize()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!