qt-material icon indicating copy to clipboard operation
qt-material copied to clipboard

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

Open MeowSalty opened this issue 1 year ago • 0 comments

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

MeowSalty avatar Mar 14 '24 12:03 MeowSalty