You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would it be possible to add a specific example for events?
That includes buttons - this is easy.
But it would be nice if more events could be showcased, such as
how to respond to mouse-click events in different widgets,
including a gtk entry and a gtk label.
And perhaps a few more examples.
This would be helpful for people who port older code from e. g. gtk3 to see
how things changed in regards to events. The new event model still
confuses me and is one reason I failed to transition into gtk4 so far.
The text was updated successfully, but these errors were encountered:
There are different controllers such as EventControllerKey, EventControllerMotion, or GestureClick. You create one and add it to whatever widget using .add_controller(controller).
So for mouse click
controller=Gtk.GestureClick.new()
controller.connect("pressed", self.click) # could be "released"controller.set_button(0) # 0 for all buttonsself.add_controller(controller) # here self is window but could be any widgetdefclick(self, gesture, data, x, y):
button=gesture.get_current_button()
print(button)
What I didn't mention which may be useful was if you want to override a widgets normal behavior such as keyboard input on a text entry box, you can do controller.set_propagation_phase(Gtk.PropagationPhase.CAPTURE) then in the callback functions, return True or False as to if you handled the event.
Hey there,
Would it be possible to add a specific example for events?
That includes buttons - this is easy.
But it would be nice if more events could be showcased, such as
how to respond to mouse-click events in different widgets,
including a gtk entry and a gtk label.
And perhaps a few more examples.
This would be helpful for people who port older code from e. g. gtk3 to see
how things changed in regards to events. The new event model still
confuses me and is one reason I failed to transition into gtk4 so far.
The text was updated successfully, but these errors were encountered: