pyqt5のQScrollAreaでウィンドウの中にスクロールされるエリアを作ろうと思います。その際、ウィンドウを立ち上げた際のスクロールエリアの初期サイズが小さいです。setFixedSizeやsetMinimumSizeを使えばサイズを指定できますが、サイズの調整に縛りが出来てしまいます。
スクロールエリアの初期サイズを指定させるにはどのようにすればよいのでしょうか。
ソースコード
import sys
from PyQt5 import QtGui,QtCore, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.Qt import *
from PyQt5.QtGui import *
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from mpl_toolkits.mplot3d import Axes3D
class Window(QWidget):
def __init__(self):
super().__init__()
val=30
self.title = "PyQt5 Scroll Bar"
self.setWindowIcon(QtGui.QIcon("icon.png"))
self.setWindowTitle(self.title)
self.figure1 = plt.figure(figsize=(4,4), dpi=100)
self.canvas1 = FigureCanvas(self.figure1)
self.axes1 = Axes3D(self.figure1)
self.canvas1.setMinimumSize(400,400)
self.figure2 = plt.figure(figsize=(4,4), dpi=100)
self.canvas2 = FigureCanvas(self.figure2)
self.axes2 = Axes3D(self.figure2)
self.canvas2.setMinimumSize(400,400)
self.figure3 = plt.figure(figsize=(4,4), dpi=100)
self.canvas3 = FigureCanvas(self.figure3)
self.axes3 = Axes3D(self.figure3)
self.canvas3.setMinimumSize(400,400)
self.figure4 = plt.figure(figsize=(4,4), dpi=100)
self.axes4 = self.figure4.add_subplot(111)
self.canvas4 = FigureCanvas(self.figure4)
self.axes4.set_aspect("equal")
self.canvas4.setMinimumSize(400,400)
self.figure5 = plt.figure(figsize=(4,4), dpi=100)
self.axes5 = self.figure5.add_subplot(111)
self.canvas5 = FigureCanvas(self.figure5)
self.axes5.set_aspect("equal")
self.canvas5.setMinimumSize(400,400)
self.figure6 = plt.figure(figsize=(4,4), dpi=100)
self.axes6 = self.figure6.add_subplot(111)
self.canvas6 = FigureCanvas(self.figure6)
self.axes6.set_aspect("equal")
self.canvas6.setMinimumSize(400,400)
self.figure7 = plt.figure(figsize=(4,4), dpi=100)
self.axes7 = self.figure7.add_subplot(111,polar=True)
self.canvas7 = FigureCanvas(self.figure7)
self.axes7.set_aspect("equal")
self.canvas7.setMinimumSize(400,400)
self.figure8 = plt.figure(figsize=(4,4), dpi=100)
self.axes8 = self.figure8.add_subplot(111,polar=True)
self.canvas8 = FigureCanvas(self.figure8)
self.axes8.set_aspect("equal")
self.canvas8.setMinimumSize(400,400)
self.figure9 = plt.figure(figsize=(4,4), dpi=100)
self.axes9 = self.figure9.add_subplot(111,polar=True)
self.canvas9 = FigureCanvas(self.figure9)
self.axes9.set_aspect("equal")
self.canvas9.setMinimumSize(400,400)
layout=QGridLayout()
layout.addWidget(self.canvas1,0,0)
layout.addWidget(self.canvas2,0,1)
layout.addWidget(self.canvas3,0,2)
layout.addWidget(self.canvas4,1,0)
layout.addWidget(self.canvas5,1,1)
layout.addWidget(self.canvas6,1,2)
layout.addWidget(self.canvas7,2,0)
layout.addWidget(self.canvas8,2,1)
layout.addWidget(self.canvas9,2,2)
groupBox = QGroupBox("Canvas")
groupBox.setLayout(layout)
scroll = QScrollArea()
scroll.setWidget(groupBox)
scroll.setWidgetResizable(True)
layout2 = QVBoxLayout()
layout2.addWidget(scroll)
self.setLayout(layout2)
self.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
mainWindow = Window()
mainWindow.show()
sys.exit(app.exec_()) # only need one app, one running event loop
#app.exec_()