简体   繁体   中英

g_signal_connect for right mouse click?

我得到了这个代码,用于鼠标左键单击按钮,但我将如何使用鼠标右键单击信号:

g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(button-action), NULL);

A simple way to listen for any mouse clicks, be it left or right would be this:

g_signal_connect(
    G_OBJECT(button)
    "button-press-event",
    G_CALLBACK(btn_press_callback),
    NULL
);

Then, for the callback function:

gboolean btn_press_callback(GtkWidget *btn, GdkEventButton *event, gpointer userdata)
{
    if (event->type == GDK_BUTTON_PRESS  &&  event->button == 3)
    {//3 is right mouse btn
        //do stuff
        return true;//or false
    }
    if (event->type == GDK_BUTTON_PRESS  &&  event->button == 1)
    {//1 is left mouse btn
    }
}

And so on... More info here .

some examples, using GTK+-2 but still useful, can be found here .

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