Seems that when the SpinButton is created, an EventControllerScroll is added too. So that users can change the value of SpinButton by scrolling.
But I often change it accidentally.
How can I remove EventControllerScroll from SpinButton? I can do this by looping Widget.observe_controllers()
and then remove it.
But the doc says:
Applications should try hard to avoid calling this function
because of the slowdowns.
So is there other better ways to stop scoll
to change the value of SpinButton?
g_signal_connect(spinbutton, “scroll-event”, G_CALLBACK(gtk_true), NULL);
ebassi
(Emmanuele Bassi)
March 23, 2023, 10:05am
#3
The scroll-event signal is only available on widgets if you’re using GTK3, but since @Charles is referring to the observe_controllers()
method, they are using GTK4.
ebassi
(Emmanuele Bassi)
March 23, 2023, 10:07am
#4
Do not ever remove internal objects from a GTK widget: things are going to break, horribly, and there is no expectation that what you do is supported in any way.
You could add a scroll event controller on the parent widget of the spin button, using the capture phase, and prevent any scroll event from reaching the spin button.
I added a Gtk.EventControllerScroll
on the parent widget GtkBox:
This is the properties on the added Gtk.EventControllerScroll
:
The code is:
_newBox(properties) {
const box = new Gtk.Box({
spacing: 6,
margin_top: 6,
margin_bottom: 6,
margin_start: 6,
margin_end: 6,
})
Object.assign(box, properties);
return box;
}
const boxLeft = this._newBox({
hexpand: true,
halign: Gtk.Align.START
});
// Add a spin button on boxLeft
boxLeft.append(this._newSpinButton());
// add a Gtk.EventControllerScroll on boxLeft
const controller = new Gtk.EventControllerScroll();
// Prevent the scroll event of the spin button inside the boxLeft? It's not working
controller.set_propagation_phase(Gtk.PropagationPhase.CAPTURE);
controller.connect('scroll', () => {
// Can't receive this event while scroll on the spin button added on the boxLeft
log('Scrolling..')
return Gdk.EVENT_STOP;
});
boxLeft.add_controller(controller);
The above code is not working. Am I missing something important?