[Python] Why can't one change the size of a PyQt checkbox?

Discussão em 'Python' iniciado por Stack, Fevereiro 10, 2025.

  1. Stack

    Stack Membro Participativo

    The following code runs, but the checkbox is tiny (it should be large). Why doesn't this work as expected? (One can use styling to resize the text, but that's not what I'm trying to do here). I'll be grateful for any suggestions.

    import sys

    from PyQt5.QtWidgets import (
    QApplication,
    QCheckBox,
    QVBoxLayout,
    QWidget,
    )

    class Window(QWidget):
    def __init__(self, parent=None):
    super().__init__(parent)

    # Create a Checkbox with a text label:
    chkBox = QCheckBox(text="Check box if you want this option.")

    # Make the checkbox large (has no effect):
    chkBox.setStyleSheet('QCheckBox::indicator {width:24px; height:24px}')

    layout= QVBoxLayout()
    layout.addWidget(chkBox)
    self.setLayout(layout)

    if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec())

    Continue reading...

Compartilhe esta Página