简体   繁体   中英

GdkEventButton when migrating from gtkmm-3.0 to gtkmm-4.0

I'm trying to get the cursor's coordinates and what type of click occurred when clicking on a button in gtkmm 4.0.

In gtkmm 3.0, I could use GdkEventButton , as in this example from the docs :

bool on_button_press(GdkEventButton* event);
Gtk::Button button("label");
button.signal_button_press_event().connect( sigc::ptr_fun(&on_button_press) );

But GdkEventButton seems to no longer exist or no longer be accessible in gtkmm 4.0.

There is a reference to GdkEvent API changes in the migration documentation , but I still do not understand how to migrate that example code.

I've made a few unsuccessful blind attempts that probably aren't helpful to reproduce here (eg swapping out GdkEventButton with GdkEvent in the example). Is anyone more familiar or has any sort of related example? Thanks!

I got an answer from Kjell linking these relevant gtkmm 4.0 examples , as well as the general advice:

In most (perhaps all) situations where event signals have been used in gtkmm3, use one of the many subclasses of Gtk::EventController.

So to answer the specific question of how to convert this gtkmm 3.0 example:

bool on_button_press(GdkEventButton* event);
Gtk::Button button("label");
button.signal_button_press_event().connect( sigc::ptr_fun(&on_button_press) );

In gtkmm 4.0 it would be something like this:

void on_button_press(int n_press, double x, double y);
Gtk::Button button("label");
Glib::RefPtr<Gtk::GestureClick> refGesture = Gtk::GestureClick::create();
refGesture->signal_pressed().connect(sigc::ptr_fun(&on_button_pressed));
button.add_controller(refGesture);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM