Skip to content

QToggleButton animation de-synced when sate changed inside QSignalBlocker #340

@carlosmariorr

Description

@carlosmariorr

Describe the bug
The QToggleSwitch class won't update the GUI if used under a QSignalBlocker.

This is happening because the animation is handled as an event connection in:

class QToggleSwitch(QtW.QAbstractButton):
    
    ....

    def __init__(  # type: ignore [misc]  # overload
        self, text: str | None = None, parent: QtW.QWidget | None = None
    ) -> None:
        
        ....

        self.toggled.connect(self._animate_handle)

To Reproduce
Steps to reproduce the behavior:

  1. Create a QToggleSwitch.
  2. Update the state inside a QSignalBlocker.
  3. The button will glitch, properly changing the color but not the GUI handle.

Expected behavior
If the button state is updated inside a QSignalBlocker, the GUI should be updated alongside the state.

Screenshots
Button state Checked = True but GUI handle OFF (WRONG state)
Image

Button state Checked = False but GUI handle ON (WRONG state)
Image

Button state Checked = False GUI handle OFF (This is CORRECT)
Image

Desktop:

  • Windows 11 (26200.8328)
  • PyQt6 (6.10.2)
  • Python 3.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions