Search code examples
qtpyqtpyside

How to make QPushButton to be in checked state by default?


I am using QPushButton.setCheckable(True), by default button is not checked, but I want it to be checked from the beginning. I couldn't find anything in the documentation.


Solution

  • As the name says, setCheckable sets if the button is checkable or not.

    setChecked() sets whether a checkable button is actually checked or not.

    Remember that most Qt classes inherit from a superclass (so it also inherits all its properties and functions), you can check the inheritance in the header of the documentation, and there's also a link named "List of all members, including inherited members".

    The full inheritance of QPushButton is:

    QPushButton > QAbstractButton > QWidget > QObject, QPaintDevice

    So, it means that QPushButtons also has all functions and properties of QAbstractButton, QWidget, QObject and QPaintDevice.
    This also means that if you really want to know what a class does, you should better study all the documentation related to all the classes it inherits from.