根本无法滚动。
应用代码:
import sys
from PyQt5.QtWidgets import QWidget, QApplication, QScrollArea, QVBoxLayout
from PyQt5.QtGui import QPainter, QColor
class TableComponents(QWidget):
def __init__(self):
self.table = []
super().__init__()
def paintEvent(self, QPaintEvent):
paint = QPainter(self)
# paint.begin(self)
height = 20
width = 20
interval = 25
i = 0
j = 0
while i < 100:
while j < 100:
paint.setBrush(QColor(50, 150, 50, 255))
paint.drawRect(i * interval + 10, j * interval + 10, height, width)
j += 1
j = 0
i += 1
class App(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
tc = TableComponents()
scroll = QScrollArea(self)
scroll.setGeometry(0, 0, 1400, 800)
scroll.setWidget(tc)
scroll.setWidgetResizable(True)
vbox = QVBoxLayout()
vbox.addWidget(scroll)
self.setLayout(vbox)
if __name__ == '__main__':
app = QApplication(sys.argv)
mainWindow = App()
mainWindow.setWindowTitle('App')
mainWindow.setGeometry(50, 50, 1200, 800)
mainWindow.show()
sys.exit(app.exec_())
尝试: