datetime:2019/5/21 16:00
author:nzb
创建滚动条
import sys
from PyQt5.QtWidgets import QWidget, QApplication, QLabel, QGroupBox, QCheckBox, \
QHBoxLayout, QFrame, QScrollArea, QFormLayout, QPushButton, QVBoxLayout
from PyQt5.QtWidgets import QSplitter, QLineEdit
from PyQt5 import QtGui, QtCore
from PyQt5.QtCore import Qt
class UI_demo(QWidget):
"""用户界面"""
def __init__(self, val):
super().__init__()
self.title = 'PyQt5 QScroll Area'
self.left = 600
self.top = 200
self.width = 500
self.height = 500
self.iconName = '../img/home.ico'
self.val = val
self.initWindow()
def initWindow(self):
self.setWindowIcon(QtGui.QIcon(self.iconName))
self.setGeometry(self.left, self.top, self.width, self.height)
self.setWindowTitle(self.title)
formLayout = QFormLayout()
groupBox = QGroupBox("This is group box")
labelList = []
buttonList = []
for i in range(self.val):
labelList.append(QLabel("Label"))
buttonList.append(QPushButton('click me'))
formLayout.addRow(labelList[i], buttonList[i])
groupBox.setLayout(formLayout)
scroll = QScrollArea()
scroll.setWidget(groupBox)
scroll.setWidgetResizable(True)
scroll.setFixedHeight(400)
layout = QVBoxLayout()
layout.addWidget(scroll)
self.setLayout(layout)
self.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
ex = UI_demo(20)
sys.exit(app.exec_())