In the example below I use setStyleSheet to align text in the label. Unfortunately, it does not work and the text is always aligned to the left. Any help to solve it is appreciated. This example is a reduction of a much larger program and therefore the QVBoxLayout() is used.
import sys
from PyQt6.QtWidgets import (QApplication, QLabel, QMainWindow, QPushButton,
QVBoxLayout, QTextEdit, QWidget
)
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Example")
layout = QVBoxLayout()
layout.setContentsMargins(10, 10, 10, 10)
layout.setSpacing(10)
self.title = QLabel("Label Text", self)
self.title.setStyleSheet ("text-align: center;")
self.output_text = QTextEdit("Text Output")
self.button1 = QPushButton("Button1")
layout.addWidget(self.title)
layout.addWidget(self.button1)
widget = QWidget()
widget.setLayout(layout)
self.setCentralWidget(widget)
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec()