[Python] QLabel css "text-align: center" is ignored

Discussão em 'Python' iniciado por Stack, Julho 22, 2025.

  1. Stack

    Stack Membro Participativo

    Contrary to the spec, CSS setting text-align: center is ignored by QLabel (other settings like font-size and color are respected):

    from PyQt6.QtWidgets import QApplication, QLabel

    app = QApplication([])

    label = QLabel("This is centered?")
    label.setStyleSheet("""
    QLabel {
    background-color: #333;
    color: orange;
    text-align: center;
    }
    """)
    label.resize(300, 100)
    label.show()

    app.exec()


    Is this a known bug? Is there a workaround?

    Continue reading...

Compartilhe esta Página