UN-GCPDS / qt-material

Material inspired stylesheet for PySide2, PySide6, PyQt5 and PyQt6
https://qt-material.readthedocs.io/en/latest/
BSD 2-Clause "Simplified" License
2.22k stars 240 forks source link

The `QPushButton` within the `QButtonGroup` still retains its color when it is not selected. #110

Open wsndshx opened 4 months ago

wsndshx commented 4 months ago

I tried using the following function to check the state when a QPushButton is clicked:

neko = ""

def buttonCat(button: QPushButton, group: QButtonGroup):
    global neko
    print(f"You clicked button {button.text()}")
    if neko == button.text():
        print("The button was clicked again.")
        group.setExclusive(False)
        for button in group.buttons():
            button.setChecked(False)
        group.setExclusive(True)
        neko = ''
    else:
        print("The button was clicked for the first time.")
        neko = button.text()

The main functionality of this function is to deselect the button when it is clicked again. Meanwhile, I'm using the following method to invoke the above function:

    # Create a QButtonGroup to manage mutually exclusive buttons.
    button_group = QButtonGroup(self)

    # Create H1 and H2 buttons.
    h1_button = QPushButton("H1")
    h1_button.setCheckable(True)
    h2_button = QPushButton("H2")
    h2_button.setCheckable(True)

    # Add the buttons to the button group.
    button_group.addButton(h1_button)
    button_group.addButton(h2_button)
    button_group.setExclusive(True)  # Set them to mutual exclusive mode, meaning only one button can be selected at a time.
    button_group.buttonClicked.connect(lambda button: buttonCat(button, button_group))

img

The behavior is normal when not using QSS.

img