[Python] PySide6 AltModifier is broken

Discussão em 'Python' iniciado por Stack, Abril 6, 2025.

  1. Stack

    Stack Membro Participativo

    So, i tried to make scrolling faster with Alt pressed, and it gives me either the strangest, or the dumbest error ever:

    dcurrent_value = current_value % scroll_amount # Snapping to nearest step (current value is any number, while accumulated scroll is fixed to steps)
    ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
    ZeroDivisionError: integer modulo by zero


    At first i thought the problem was with step_size, but after a bit of testing it was not it. Then i tried to change & to is/in/==, didnt work either. So i just added another modifier, Shift, and it started working just fine. Whats up with AltModifier?

    def wheelEvent(self, event):
    modifiers = event.modifiers()
    if modifiers & Qt.KeyboardModifier.AltModifier: # Use == instead of &
    step_size = self.step_size * self.alt_multiplier
    elif modifiers & Qt.KeyboardModifier.ShiftModifier: # Keep & for Shift since it works
    step_size = self.step_size * self.alt_multiplier
    else:
    step_size = self.step_size
    delta = event.angleDelta().y()
    scroll_amount = round(-delta / 120 * step_size * self.scale_multiplier) # Float error

    # Reset or accumulate scroll based on direction change
    if self.prev_delta != delta:
    self.accumulated_scroll = 0
    self.accumulated_scroll += scroll_amount

    current_value = self.scroll_bar.value()
    dcurrent_value = current_value % scroll_amount # Snapping to nearest step (current value is any number, while accumulated scroll is fixed to steps)

    Continue reading...

Compartilhe esta Página