PyQt scrollAreaサンプル
#!/usr/bin/python # -*- coding: utf-8 -*- import sys from PyQt4.QtCore import * from PyQt4.QtGui import * class Example(QMainWindow): def __init__(self, parent=None): super(Example, self).__init__(parent) self.setWindowTitle("Main Window") self.resize(200, 100) self.scrollArea = QScrollArea() self.base = QLabel() self.base.setPixmap(QPixmap("aaa.png")) self.scrollArea.setWidget(self.base) self.setCentralWidget(self.scrollArea) def main(): app = QApplication(sys.argv) win = Example() win.show() sys.exit(app.exec_()) if __name__ == '__main__': main()
scrollAreaはsetWidgetしかないから
複数Widgetを入れるには
self.scrollArea = QScrollArea() self.base = QWidget() self.layout = QHBoxLayout(self.base) #self.layout = QHBoxLayout() #self.base.setLayout(self.layout) #という書き方もアリ self.label1 = QLabel() self.label1.setPixmap(QPixmap("aaa.png")) self.label2 = QLabel() self.label2.setPixmap(QPixmap("bbb.png")) self.layout.addWidget(self.label1) self.layout.addWidget(self.label2) self.scrollArea.setWidget(self.base) self.setCentralWidget(self.scrollArea)
こんなかんじ?