How to limit maximum height of GtkListBox inside of GtkGrid?

So I’m trying to make an app with checkboxes with the buttons on the bottom of the window.
The problem is that the list extends vertically when I add a lot of items and it moves the buttons and extends window vertically, too. Is there some workarounds about it?

Here’s my window.ui (minimal, without things that don’t matter):

<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <template class="ExampleApp" parent="GtkApplicationWindow">
    <property name="title">Example App</property>
    <child>
      <object class="GtkGrid" id="gtk_box">
        <child>
          <object class="GtkGrid">
            <layout>
              <property name="column">0</property>
              <property name="row">0</property>
            </layout>
            <child>
              <object class="GtkListBox" id="mod_list">
                <property name="visible">True</property>
                <property name="width-request">320</property>
                <property name="overflow">1</property>
                <property name="vexpand">false</property>
                <property name="height-request">320</property>
                <property name="selection-mode">none</property>
                <style>
                  <class name="boxed-list" />
                </style>
              </object>
            </child>
            <child>
            <object class="GtkGrid">
              <layout>
                <property name="column">1</property>
                <property name="row">0</property>
              </layout>
              <child>
                <object class="GtkButton">
                  <property name="label">Button 1</property>
                  <layout>
                    <property name="column">0</property>
                    <property name="row">0</property>
                  </layout>
                </object>
              </child>
              <child>
                <object class="GtkButton">
                  <property name="label">Button 1</property>
                  <layout>
                    <property name="column">0</property>
                    <property name="row">1</property>
                  </layout>
                </object>
              </child>
              <child>
                <object class="GtkButton">
                  <property name="label">Button 1</property>
                  <layout>
                    <property name="column">0</property>
                    <property name="row">2</property>
                  </layout>
                </object>
              </child>
              <child>
                <object class="GtkButton">
                  <property name="label">Button 1</property>
                  <layout>
                    <property name="column">0</property>
                    <property name="row">3</property>
                  </layout>
                </object>
              </child>
            </object>
            </child>
        </object>
      </child>
        <child>
          <object class="GtkGrid">
          <layout>
            <property name="column">0</property>
            <property name="row">1</property>
          </layout>
        <child>
          <object class="GtkButton">
            <property name="label">Save</property>
            <layout>
              <property name="column">0</property>
              <property name="row">0</property>
            </layout>
          </object>
        </child>
        <child>
          <object class="GtkButton">
            <property name="label">Save and Play</property>
            <layout>
              <property name="column">0</property>
              <property name="row">1</property>
            </layout>
            <property name="action-name">win.check_mod</property>
          </object>
        </child>
      </object>
        </child>
      </object>
    </child>
  </template>
</interface>

As you might have noticed, I tried to use properties overflow: 1 and vexpand (both false and False) but that didn’t work.

Demo

Update: I will probably replace GtkListBox with GtkColumnView Gtk.ColumnView

Using a GtkScrolledWindow actually limited the width and height of the GtkListBox and made it scrollable.

Here’s an example of the layout (needs tweaking to make it look better)

<object class="GtkScrolledWindow">
  <child>
    <object class="GtkListBox" id="mod_list">
      <property name="visible">True</property>
      <property name="width-request">320</property>
      <property name="overflow">1</property>
      <property name="vexpand">false</property>
      <property name="height-request">320</property>
      <property name="selection-mode">none</property>
      <style>
        <class name="boxed-list" />
      </style>
    </object>
  </child>
</object>

Hi,

A few tips:

  • visible is already true by default
  • vexpand is already false by default
  • overflow should not be needed here, it has no impact on widget sizing
  • for guaranteeing a minimal size, width/height-request shall be applied on the scrolledwindow instead
  • you can use hscrollbar-policy = never to avoid horizontal scrolling (it seems you need only vertical scrolling in your example)
<object class="GtkScrolledWindow">
  <property name="width-request">320</property>
  <property name="height-request">320</property>
  <property name="hscrollbar-policy">never</property>
  <child>
    <object class="GtkListBox" id="mod_list">
      <property name="selection-mode">none</property>
      <style>
        <class name="boxed-list" />
      </style>
    </object>
  </child>
</object>
1 Like

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