PyQt4 QScrollArea 滚动条

1.

#!/usr/bin/python

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

app = QApplication(sys.argv)
win = QMainWindow()

realmScroll = QScrollArea(win)
win.setCentralWidget(realmScroll)
realmScroll.setWidgetResizable(True)

labelsContainer = QWidget()
realmScroll.setWidget(labelsContainer)
labelsLayout = QVBoxLayout(labelsContainer)

for i in range(1, 20):
 label = QLabel("test #" + str(i))
 labelsLayout.addWidget(label)

 

win.show()
app.exec_()

 

2.

#!/usr/bin/python


import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class Test(QMainWindow):

    def __init__(self):
        QMainWindow.__init__(self)
        self.realmScroll = QScrollArea(self)
        self.setCentralWidget(self.realmScroll)
        self.realmScroll.setWidgetResizable(True)

        labelsContainer = QWidget()
        self.realmScroll.setWidget(labelsContainer)
        labelsLayout = QVBoxLayout(labelsContainer)

        for i in range(1, 20):
            label = QLabel("test #" + str(i))
            labelsLayout.addWidget(label)

app = QApplication(sys.argv)
test = Test()
test.show()
app.exec_()

你可能感兴趣的:(PyQt4)