Stop Thinking in Rows: GListModel and GTK4 ListView
Explore how GTK4 handles modern lists using GListModel and ListView, separating data from UI, and when to use GtkListBox.

Stock photo for illustration only, not from the actual event
- Third entry in A Field Guide to GTK Widgets focusing on list implementations
- Shift from manual row manipulation to GListModel and GtkListView architecture
- Clear guidance on when to use GListModel versus traditional GtkListBox
This is the third entry in A Field Guide to GTK Widgets, a series exploring which widget to reach for and the pitfalls you might encounter, jumping straight to lists ahead of layout and navigation because reference documents handle this poorly. Complete and runnable code is available in the companion repository.
Imagine displaying a handful of tasks. The intuitive loop-and-append approach requires manual maintenance whenever data changes—such as re-sorting completed tasks to the bottom or filtering rows via a toggle. You find the right row, remove it, rebuild it, and reinsert it at the correct index without making mistakes. This kind of code often passes initial testing only to break three weeks later.
This exact pain point drove GTK4's redesign, replacing deprecated components like GtkTreeView, GtkListStore, and cell renderers. The modern approach inverts this relationship: instead of mutating a widget tree by hand, you store your data in a list model implementing the GListModel interface, allowing the view to watch it automatically.
GListModel is not a widget; it is an interface implemented by any GObject to indicate an ordered, indexable collection that reports changes. The concrete type you will reach for constantly is GListStore, a mutable in-memory list model.
"describe the relationship between data and widget once, and let the toolkit run it."
Separating data and view means their respective files should reflect that boundary. For instance, data modules do not import GTK at all. Data remains purely data, requiring selection models and factories to render items onto the screen.
The architectural shift to GListModel and ListView in GTK4 mirrors modern software design principles by cleanly decoupling Model from View, drastically reducing UI synchronization bugs and improving long-term application maintainability.
However, GtkListBox is not deprecated. It remains the correct tool for short, mostly static lists such as settings pages or preference groups, where scale and volatility are low rather than correctness.
Source: Dev.to
Found something wrong in this article? Report an issue with this article
Comments
Leave a Comment