PyQt5的QScrollArea组件为一种控件容器,它的的作用是可以容纳更多的组件,如果组件过多会出现滚动条,滚动条会根据容器的大小与内部组件的大小变化。
使用方法可以参考如下实例
import sys
from PyQt5.QtWidgets import *
class test(QWidget):
def __init__(self):
super().__init__()
self.initui()
def initui(self):
la=QHBoxLayout()
lb=QVBoxLayout()
lc=QHBoxLayout()
scroll=QScrollArea()
a=QWidget()
a.setLayout(lb)
lb.addLayout(lc)
for x in range(50):
lb.addWidget(QPushButton(str(x)))
for x in range(50):
lc.addWidget(QPushButton(str(x)))
scroll.setMinimumSize(400,400)
#scrollarea 作为一个组件,可以设置窗口
scroll.setWidget(a)
la.addWidget(scroll)
self.setLayout(la)
self.show()
if __name__=='__main__':
app=QApplication(sys.argv)
win=test()
sys.exit(app.exec_())
运行结果为
版权声明:本文为xhh22900原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。