[Solved] Libgtk+-2.0 - Customize the width of a GtkVScrollbar

Hi,
I would love to implement a GUI scale-factor and didn’t figure out howto change the width of a GtkVScrollbar.

As packed to a GtkTable it only showed a padding and filled up using empty space.

  cell_pattern->vscrollbar = (GtkVScrollbar *) gtk_vscrollbar_new(adjustment);
  gtk_widget_set_size_request(cell_pattern->vscrollbar,
                              gui_scale_factor * 16, AGS_CELL_PATTERN_MAX_CONTROLS_SHOWN_VERTICALLY * cell_pattern->cell_height + 1);
  gtk_table_attach((GtkTable *) cell_pattern,
                   (GtkWidget *) cell_pattern->vscrollbar,
                   1, 2,
                   0, 1,
                   GTK_FILL, GTK_FILL,
                   0, 0);

Further, I do this during program start:

  if(!builtin_theme_disabled){
    g_object_set(gtk_settings_get_default(),
                 "gtk-theme-name", "Raleigh",
                 NULL);
    g_signal_handlers_block_matched(gtk_settings_get_default(),
                                    G_SIGNAL_MATCH_DETAIL,
                                    g_signal_lookup("set-property",
                                                    GTK_TYPE_SETTINGS),
                                    g_quark_from_string("gtk-theme-name"),
                                    NULL,
                                    NULL,
                                    NULL);
  }

So howto draw a GtkVScrollbar with increased width?


by Joël

There’s no such thing as a “set-property” signal: the set_property() virtual function of GObjectClass does not have a corresponding signal. This means you’re not blocking anything. Additionally, you cannot block the implementation of GObjectClass.set_property() from the outside of a class.

This is not really possible within GTK 2.0; there’s a lot of work underneath the scaling factor in GTK 3, and in various cases the API and the internal implementation of entire widgets had to be changed. Plus, you cannot really implement this from behind the toolkit’s back.

The width of a scrollbar is partially determined by the style, using the slider-width style property.

Hi ebassi,

I am not sure what you want to tell. It seems to work, you can’t change the theme of the application from outside.

Thank you, I didn’t look at GtkRange …

That’s because settings set by the application have a higher priority, and will supersede any setting set from an outside source.

I try to figure out howto set style property on Gtk±2.0. Might be I have a need for a quark :slight_smile:

I am just curious about if there is GtkSettings property that I can use …

I think slider-width is stylable.

No, there isn’t one. As I said: what you want to achieve is simply not possible with GTK 2, unless you’re writing your own widgets with their own size_request/size_allocate implementation.

This did it actually:

  if(!builtin_theme_disabled){
    gchar *str;

    gdouble gui_scale_factor;

    gui_scale_factor = 1.0;

    str = ags_config_get_value(config,
                               AGS_CONFIG_GENERIC,
                               "gui-scale");

    if(str != NULL){
      gui_scale_factor = g_ascii_strtod(str,
                                        NULL);

      g_free(str);
    }

    str = g_strdup_printf("style \"ags-default-vscrollbar-style\"\n{\n\tGtkVScrollbar::slider-width = %d\n}\n\nwidget_class \"*<GtkVScrollbar>*\" style \"ags-default-vscrollbar-style\"\n",
                          (gint) (gui_scale_factor * 14));
    gtk_rc_parse_string(str);
    g_free(str);
  }

Thought, I can do even better:

  /* some scaling */
  if(!builtin_theme_disabled){
    GParamSpec *param_spec;

    gchar *str;

    gdouble gui_scale_factor;
    gint default_slider_width;
    gint default_stepper_size;

    GValue *value;

    gui_scale_factor = 1.0;

    str = ags_config_get_value(config,
                               AGS_CONFIG_GENERIC,
			       "gui-scale");

    if(str != NULL){
      gui_scale_factor = g_ascii_strtod(str,
                                        NULL);

      g_free(str);
    }

    /* horizontal scrollbar */
    default_slider_width = 14;
    default_stepper_size = 14;

    param_spec = gtk_widget_class_find_style_property(g_type_class_ref(GTK_TYPE_VSCROLLBAR),
                                                      "slider-width");
    value = g_param_spec_get_default_value(param_spec);

    if(value != NULL){
      default_slider_width = g_value_get_int(value);
    }

    param_spec = gtk_widget_class_find_style_property(g_type_class_ref(GTK_TYPE_VSCROLLBAR),
                                                      "stepper-size");
    value = g_param_spec_get_default_value(param_spec);

    if(value != NULL){
      default_stepper_size = g_value_get_int(value);
    }

    str = g_strdup_printf("style \"ags-default-vscrollbar-style\"\n{\n\tGtkVScrollbar::slider-width = %d\nGtkVScrollbar::stepper-size = %d\n}\n\nwidget_class \"*<GtkVScrollbar>*\" style \"ags-default-vscrollbar-style\"\n",
                          (gint) (gui_scale_factor * default_slider_width),
                          (gint) (gui_scale_factor * default_stepper_size));
    gtk_rc_parse_string(str);
    g_free(str);

    /* vertical scrollbar */
    default_slider_width = 14;
    default_stepper_size = 14;

    param_spec = gtk_widget_class_find_style_property(g_type_class_ref(GTK_TYPE_HSCROLLBAR),
                                                      "slider-width");
    value = g_param_spec_get_default_value(param_spec);

    /* ... */
}

by Joel

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