David van Wyk
David van Wyk

Reputation: 11

Gtk+3 GtkBuilder UI/XML restrict widget size

I am busy with a project on a raspberry pi, using g++ and GtkBuilder.

This is not my normal programming environment so I got stuck with a rather simple problem, to specify different sizes for two objects in a container. Say the first Button should be 10% of the Window height and the second button can be uspecified, that would default to 90% then.

I would like to create the widgets in a UI or XML file, therefor

gtk_widget_set_size_request(widget,width,height); 

is NOT the answer I am looking for. Below is my sample code,

<interface>
  <object id="window" class="GtkWindow">
    <property name="title">Window</property>
    <property name="border-width">10</property>
    <child>
      <object id="mainbox" class="GtkVBox">
        <property name="visible">True</property>
        <property name="homogeneous">False</property>
        <child>
          <object id="button1" class="GtkButton">
            <property name="label">Button1</property>
          </object>
        </child>   
        <child>
          <object id="button2" class="GtkButton">
            <property name="label">Button2</property>
          </object>
        </child>      
      </object>         
    </child>
  </object>
</interface>

I've tried:

<property name="default_height">100</property>

<property name="request_height">100</property>

I can't seem to find much information on the XML/UI side on the web.

Upvotes: 0

Views: 849

Answers (2)

Shadow_m2
Shadow_m2

Reputation: 397

You are using the wrong name for the property. In the documentation you can see that the property names are "width-request" and "height-request". This actually solved my problem, too.

Upvotes: 2

David van Wyk
David van Wyk

Reputation: 11

I found some info on my own question, GtkVbox and GtkHbox is apparently soon to be depricated, nevertheless,

<property name="request-height">500</property>

on the larger button, in my case the bottom one, will request more space than the top button, therefor squeezing up the top button. Still not ideal since you have to know the screen size.

GtkGrid however works much better with packing as in my altered code below

<interface>
  <object id="window" class="GtkWindow">
    <property name="title">Window</property>
    <property name="border-width">10</property>
    <child>
      <object id="mainbox" class="GtkGrid">
        <property name="visible">True</property>
        <property name="row-homogeneous">True</property>
        <child>
          <object id="button1" class="GtkButton">
            <property name="label">Button1</property>
          </object>
          <packing>
            <property name="top-attach">0</property>
            <property name="height">1</property>
          </packing>
        </child>   
        <child>
          <object id="button2" class="GtkButton">
            <property name="label">Button2</property>
          </object>
          <packing>
            <property name="top-attach">1</property>
            <property name="height">9</property>
          </packing>
        </child>      
      </object>         
    </child>
  </object>
</interface>

I Hope it helps someone.

Upvotes: 0

Related Questions