In GTK3, How do I set the mouse cursor to cross hair when hovering over a GtkWidget, in this case a GtkDrawingArea?
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
First of all, you must tell the
GtkDrawingArea
widget to use a backing window, in order to receive events:Then you must tell it which events you wish to subscribe to; in this case, you want the crossing events, in order to receive notification of the pointer entering and leaving the widget:
At this point, you can connect to the
GtkWidget::enter-notify-event
andGtkWidget::leave-notify-event
signals:You can use two separate signal handlers, if you want, but unless you're doing something complex in them, the code is going to be pretty much identical.
The
on_crossing()
handler will look something like this:Now you have specify the cursor to use depending on the event type. GTK+ uses the same cursor names as CSS does; you need to create a cursor instance using one of those names and then associate it to the
GdkWindow
used by the drawing area widget: