-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScrollLabel.py
45 lines (33 loc) · 1.1 KB
/
ScrollLabel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# importing libraries
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QLabel, QScrollArea, QVBoxLayout, QWidget
"""
Code from geeksforgeeks
PyQt5 – Scrollable Label
https://www.geeksforgeeks.org/pyqt5-scrollable-label/
"""
# class for scrollable label
class ScrollLabel(QScrollArea):
# constructor
def __init__(self, *args, **kwargs):
QScrollArea.__init__(self, *args, **kwargs)
# making widget resizable
self.setWidgetResizable(True)
# making qwidget object
content = QWidget(self)
self.setWidget(content)
# vertical box layout
lay = QVBoxLayout(content)
# creating label
self.label = QLabel(content)
# setting alignment to the text
alin = Qt.AlignmentFlag
self.label.setAlignment(alin.AlignLeft | Qt.AlignmentFlag.AlignTop)
# making label multi-line
self.label.setWordWrap(True)
# adding label to the layout
lay.addWidget(self.label)
# the setText method
def setText(self, text):
# setting text to the label
self.label.setText(text)