[GTK4.x] scrollbar and g_signal_connect

I’m trying to intercept a change in the scrollbar with g_signal_connect.

I’ve tried everything possible, including 'changed-value'.

(gtk_activate:9162): GLib-GObject-WARNING **: 14:22:27.321: ../../../gobject/gsignal.c:2613: signal 'changed-value' is invalid for instance '0x562282fbc370' of type 'GtkScrollbar'

Anyone have any idea how this works?

static void print_hello (GtkWidget *widget, gpointer data)
{
  g_print ("Hello World\n");
}

int main () {
...
  GtkAdjustment *adj = gtk_adjustment_new(1, -100, 100, 0.1, 10, 0);
  GtkWidget     *sb  = gtk_scrollbar_new(GTK_ORIENTATION_VERTICAL, adj);
  gtk_box_append(GTK_BOX(box), sb);
  g_signal_connect (sb, "changed-value", G_CALLBACK (print_hello), NULL);
...

The “changed-value” signal is on the Adjustment, not on the Scrollbar :slight_smile:

1 Like

The “changed-value” signal is on the Adjustment, not on the Scrollbar :slight_smile:

  g_signal_connect (adj, "changed-value", G_CALLBACK (print_hello), NULL);
(gtk_activate:3911): GLib-GObject-WARNING **: 15:04:31.634: ../../../gobject/gsignal.c:2613: signal 'changed-value' is invalid for instance '0x564243483910' of type 'GtkAdjustment'

I also tried the following, there is no warning, but the callback is not called.

g_signal_connect (adj, "changed", G_CALLBACK (print_hello), NULL);

There is a button further down.

  GtkWidget *button1 = gtk_button_new_with_label("Button 1");
  gtk_box_append(GTK_BOX(box), button1);
  g_signal_connect (button1, "clicked", G_CALLBACK (print_hello), NULL);

Ah sorry, my bad, it’s also called value-changed

1 Like

g_signal_connect (adj, “changed-value”, G_CALLBACK (print_hello), NULL);

Adustment is okay, but the signal’s name is wrong, it should be value-changed.

Thank you, the event is now called.

I have adjusted the proc. As described here: Gtk.Adjustment::value-changed

static void scroll_Changed (GtkAdjustment *adj, gpointer user_data)
{
double val = gtk_adjustment_get_value(adj);
g_print("Value: %f\n", val);
}
....
GtkAdjustment *adj = gtk_adjustment_new(1, -100, 100, 0.1, 10, 0);
GtkWidget *sb = gtk_scrollbar_new(GTK_ORIENTATION_VERTICAL, adj);
gtk_box_append(GTK_BOX(box), sb);
g_signal_connect (adj, "value-changed", G_CALLBACK (scroll_Changed), NULL);

You have to come up with the idea that you have to use GtkAdjustment for g_signal_connect.
I read about it here, but I don’t realize it.

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