GtkListBoxRow signal

Hello everyone

I have a GtkListBox with a GtkListBoxRow. Same as the left panel of Gnome Contact.
What signal is emitted when hovering the mouse over GtkLisBoxRow so that I can do the same effect as Gnome Contact, to display a GtkCheckButton
I’ve tried enter-notify-event and leave-notify-event but it didn’t work.

In GTK3, GtkListBoxRow doesn’t receive events because it doesn’t have its own GdkWindow. In general, you can connect to event signals on the GtkListBox, and call gtk_list_box_get_row_at_y().

Contacts takes advantage of the fact that GtkListBox already does this to update the row’s state: https://gitlab.gnome.org/GNOME/gnome-contacts/-/blob/master/src/contacts-contact-list.vala#L88-94

Another option would be to insert a GtkEventBox between the GtkListBoxRow and its child.

2 Likes

My friend thanks for the tip. Now it worked. I connected the state-flags-changed signal. and now it works. By hovering the mouse over the GtkListBoxRow I can display my GtkCheckButton.

static void
on_box_row_houver (GtkWidget *object,
				   GtkStateFlags flags,
                   gpointer      user_data)
{
	FncBoxRowView *row;
	
	
	
	row = FNC_BOX_ROW_VIEW (user_data);
		
	if (flags == 128)
	 gtk_revealer_set_reveal_child (GTK_REVEALER (row->revealer), TRUE);
	else
		gtk_revealer_set_reveal_child (GTK_REVEALER (row->revealer), FALSE);

}

However if I check the GTK_STATE_FLAG_PRELIGHT it does not work because the flags return the numbers 128 o move the mouse over the GtkListBoxRow and 130 when the mouse leaves the GtkListBoxRow

Don’t work.

static void
on_box_row_houver (GtkWidget *object,
			       GtkStateFlags flags,
                   gpointer      user_data)
{
	FncBoxRowView *row;
	
	
	
	row = FNC_BOX_ROW_VIEW (user_data);
		
	if (flags == GTK_STATE_FLAG_PRELIGHT)
	 gtk_revealer_set_reveal_child (GTK_REVEALER (row->revealer), TRUE);
	else
		gtk_revealer_set_reveal_child (GTK_REVEALER (row->revealer), FALSE);

}

I researched and found that 128 is Gdk Cursor Type Target and 130 Gdk Cursor Type Cross

This code work

static void
on_box_row_houver (GtkWidget *object,
GtkStateFlags flags,
gpointer user_data)
{
FncBoxRowView *row;

row = FNC_BOX_ROW_VIEW (user_data);
	
if (flags == GDK_TARGET)
 gtk_revealer_set_reveal_child (GTK_REVEALER (row->revealer), TRUE);
else
	gtk_revealer_set_reveal_child (GTK_REVEALER (row->revealer), FALSE);

}

but it shows warning:
…/src/gui/fnc-box-row-view.c:44:12: warning: comparison between ‘GtkStateFlags’ {aka ‘enum ’} and ‘enum ’ [-Wenum-compare]
44 | if (flags == GDK_TARGET)

GdkCursor is an unrelated enum type that just happens to contain matching values.

GtkStateFlags is not a regular enum type, but a collection of bit flags (as indicated by the suffix ‘Flags’)

To test if GTK_STATE_FLAG_PRELIGHT is set in flags, you can use bitwise AND:

if (flags & GTK_STATE_FLAG_PRELIGHT) { ... }

For the record, the value 130 of GtkStateFlags is:
GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_DIR_LTR

Thank you my friend. It’s work.

GtkStateFlags flag = gtk_widget_get_state_flags (GTK_WIDGET (row)); 	
if (flag & GTK_STATE_FLAG_PRELIGHT)
   gtk_revealer_set_reveal_child (GTK_REVEALER (row->revealer), TRUE);
else
   gtk_revealer_set_reveal_child (GTK_REVEALER (row->revealer), FALSE);

if (flag & GTK_STATE_FLAG_SELECTED)
   gtk_revealer_set_reveal_child (GTK_REVEALER (row->revealer), TRUE);

You could shorten that to something like this if you like:

gtk_revealer_set_reveal_child (GTK_REVEALER (row->revealer),
    (flag & (GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_SELECTED)) != 0);

Also, I’m not sure why you’re calling gtk_widget_get_state_flags() if you’re in a state-flags-changed signal handler where that is provided for you as an argument.

If I don’t get the gpointer state flag I have a bag.
If I put the mouse on top of the row it doesn’t activate, just when I leave the mouse on top of the row it displays the check button

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.