-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
46 lines (37 loc) · 1.23 KB
/
Copy pathexample.py
File metadata and controls
46 lines (37 loc) · 1.23 KB
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
46
from PySide6.QtWidgets import QApplication, QLabel, QVBoxLayout, QWidget
from PySide6.QtCore import Qt
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
# Create a QLabel with long text
label = QLabel(
"This is a very long text that should wrap to the next line when it exceeds the width of the QLabel."
)
# Enable word wrap
label.setWordWrap(True)
label.setAlignment(Qt.AlignTop | Qt.AlignLeft)
# Optional: Set fixed width for demonstration
label.setFixedWidth(300)
# Style the QLabel (optional)
label.setStyleSheet("""
QLabel {
font-size: 14px;
color: #333;
border: 1px solid #ccc;
padding: 5px;
}
""")
# Layout
layout = QVBoxLayout()
layout.addWidget(label)
self.setLayout(layout)
self.setWindowTitle("QLabel Word Wrap Example")
self.resize(400, 200)
# Run the application
if __name__ == "__main__":
app = QApplication([])
window = MainWindow()
window.show()
app.exec()