Is it possible to place "+" and "-" buttons either side of GtkSpinButton value?

When I set a GtkSpinButton to be in vertical orientation, the “+” and “-” buttons are quite logically placed above and below the value. But in the horizontal orientation they are both placed to the right of the value, which makes for poor usability on a touch screen; the buttons end up being right next to each other, where it is easy to press the wrong one by mistake. Far better would be to have the buttons either side of the value, to increase the distance between them. But I haven’t been able to find a (simple) way of doing this - do I have to roll my own SpinButton class to achieve it, or is there a way to make the native one play nice?

Edit: I should perhaps point out that I am mainly using Glade to generate the GUI XML, which I am happy to edit by hand when what I want to do isn’t possible in Glade. CSS is also happily employed. But I’d really like to keep the (Python) program logic away from doing GUI work, as far as possible. Separation of concerns and all that.

Nope, that’s just not how GtkSpinButton places its buttons.

In this case, you need to make a custom widget that mimics the behaviour.
May be you can file this as a feature request, to allow spin button to have the increment and decrement buttons placed on either side.

1 Like

Ugh, ok. It does look like it would be relatively easy to implement a third “orientation” option on the GTKSpinButton (e.g. “alongside”) - from gtkspinbutton.c:

  /* change alignment if it's the default */
  if (spin->orientation == GTK_ORIENTATION_VERTICAL &&
      gtk_editable_get_alignment (editable) == 0.0)
    gtk_editable_set_alignment (editable, 0.5);
  else if (spin->orientation == GTK_ORIENTATION_HORIZONTAL &&
           gtk_editable_get_alignment (editable) == 0.5)
    gtk_editable_set_alignment (editable, 0.0);

  if (spin->orientation == GTK_ORIENTATION_HORIZONTAL)
      /* Current orientation of the box is vertical! */
      gtk_widget_insert_after (spin->up_button, GTK_WIDGET (spin), spin->down_button);
      /* Current orientation of the box is horizontal! */
      gtk_widget_insert_before (spin->up_button, GTK_WIDGET (spin), spin->entry);

  layout_manager = GTK_BOX_LAYOUT (gtk_widget_get_layout_manager (GTK_WIDGET (spin)));
  gtk_orientable_set_orientation (GTK_ORIENTABLE (layout_manager), spin->orientation);

But that’s not perfectly logical. What would make more sense would be to have a completely new property, like “arrangement”, with three options, “at_start”, “at_end” and “either_side”. I fear either is beyond me at this stage, so I’ll just stick with using vertical spinbuttons for now.

1 Like

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