GtkSpinButton set_range from xml

Hello community,
I started learning GTK dev for a week now. some times i get stuck and waste so much time for a simple task due to the lack of examples (especially using builder). So my last problem is trying to set the range of a GtkSpinButton in the docs there is a method to set the range of the widget but i don’t know how to do it from xml. I can get the object and set range using python but i want to do it directly using xml.

My first question is how can i do it.

Second is there a common pattern i should follow with builder like properties are translated to a property tag with name=“the name of the property” and the value. I have tried to create a property <method name="set_range">10.0, 100.0 </method> I’m improvising a bit. same goes for signals each time i find an example with different properties.

Hello, that is a good question. To configure the range, set the adjustment property and then set the values inside it:

<object class="GtkSpinButton">
  <property name="adjustment">
    <object class="GtkAdjustment">
      <property name="lower">0</property>
      <property name="upper">100<property>
      <property name="step-increment">1</property>
      <property name="page-increment">10</property>
      <property name="value">1</property>
    </object>
  </property>
</object>

To make a range that starts at 1 and goes from 0 - 100.

There is not really a common pattern outside of using <property> and <signal> tags, and then a few extra things for widgets. Those are standard so they should work in most cases. If another widget supports custom elements, the documentation will say what those are in a section describing the GtkBuildable usage.

1 Like

Thank you for answering my questions.

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