Question Details

No question body available.

Tags

python gtk pygobject gtk4

Answers (1)

March 2, 2026 Score: 2 Rep: 41 Quality: Low Completeness: 60%

I got the answer from an IRC channel, the solution is to call .setvexpand(True) on both the ScrolledWindow and the ColumnView instead of the setvalign and setpropagatenatural* calls, which gives the fixed following code :

#!/usr/bin/python3

import gi gi.require
version("Gtk", "4.0") from gi.repository import Gtk, Gio, GObject, GLib

class TestItem(GObject.Object): gtypename = "TestItem" name = GObject.Property(type=str) value = GObject.Property(type=int)

def init(self, name: str, value: int): super().init() self.name = name self.value = value

def make
tablecolumn(title, field): """ Make a column for a field """ template = b"""

GtkListItem

""" % (field.encode('ascii'),) template = GLib.Bytes.new(template) factory = Gtk.BuilderListItemFactory.new
frombytes(None, template) col = Gtk.ColumnViewColumn(title = title, factory = factory, resizable = True) return col

class Test(Gtk.ApplicationWindow): def init(self, kargs): super().
init(kargs, title="Test")

vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5)

control = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5) control.append(Gtk.Label(label = "Name:")) self.name = Gtk.Entry() control.append(self.name) control.append(Gtk.Label(label = "Value:")) self.value = Gtk.SpinButton.new
withrange(1, 100, 1) control.append(self.value) button = Gtk.Button.newfromiconname('list-add') button.connect("clicked", self.add) control.append(button) vbox.append(control)

self.model = Gio.ListStore(itemtype = TestItem) view = Gtk.ColumnView() self.selection = Gtk.NoSelection(model = self.model) view.setmodel(self.selection)

view.appendcolumn(maketablecolumn("Item name", 'name')) view.appendcolumn(maketablecolumn("Value", 'value')) view.setvexpand(True)

scroll = Gtk.ScrolledWindow() scroll.set
child(view) scroll.setvexpand(True) vbox.append(scroll)

buttons = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5) clear = Gtk.Button.new
fromiconname('edit-clear') clear.connect("clicked", self.clear) clear = Gtk.Button.newfromiconname('list-add') clear.connect("clicked", self.increase) buttons.append(clear) vbox.append(buttons)

self.set
child(vbox) self.setdefaultsize(600, 400)

def add(self, widget): name = self.name.getbuffer().gettext() value = int(self.value.getvalue()) item = TestItem(name, value) self.model.insert(0, item)

def increase(self, widget): for item in self.model: item.value += 1

def clear(self,
widget): self.model.removeall()

def on
activate(app): win = Test(application=app) win.present()

app = Gtk.Application(applicationid='org.kilobug.test') app.connect('activate', onactivate) app.run(None)