I need disable scrollwheel in gtk.scale (Gtk4&Python)

I want to create Gtk.Scale that responds only to the “released” event and does not respond to scrolling with a mouse wheel
For the first part I did:

        gesture = Gtk.GestureClick.new()
        ls_ctrls = scale.observe_controllers()
        for ctrl in ls_ctrls:
            if isinstance(ctrl, Gtk.GestureClick): gesture = ctrl      
        gesture.connect("released", on_scale_move_changed)

As for disabling scrollwheel response, I did not find a solution
Is there anything that can be done?

Hi,

You can use an event controller to filter out some incoming events:

  • create a Gtk.EventControllerScroll to capture scrolls
  • make sure to set its propagation phase to “capture”
    • (note: it may be necessary to connect the event controller to the Scale’s parent, to be sure to catch the event before it reaches the default handler)
  • connect to its ::scroll event, and return Gdk.EVENT_STOP to prevent further propagation
1 Like

Thank you very much, it worked

1 Like

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.