Repository navigation
Python: How to define TableColumns for a ListModel
#13423
Answered
by
aashishrajdev
lars-sorgalla
asked this question in
Q&A
|
Hello, On Slint side the ListModel is used as a On a side note: having an example somewhere in the docs for this would be great. |
Answered by
aashishrajdev
Sep 15, 2026
Replies: 1 comment 1 reply
|
app.slint import { StandardTableView } from "std-widgets.slint";
export component MainWindow inherits Window {
in property <[TableColumn]> columns;
in property <[[StandardListViewItem]]> rows;
StandardTableView {
columns: root.columns;
rows: root.rows;
}
}main.py import slint
from slint.language import SortOrder, StandardListViewItem, TableColumn
ui = slint.load_file("app.slint").MainWindow()
ui.columns = slint.ListModel([
TableColumn(title="Name", min_width=120.0, horizontal_stretch=1.0, sort_order=SortOrder.unsorted),
TableColumn(title="Age", sort_order=SortOrder.unsorted),
])
ui.rows = slint.ListModel([
slint.ListModel([StandardListViewItem(text="Alice"), StandardListViewItem(text="31")]),
slint.ListModel([StandardListViewItem(text="Bob"), StandardListViewItem(text="42")]),
])
ui.run()A few notes:
|
1 reply
Answer selected by
lars-sorgalla
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TableColumnis a built-in struct, so from Python it works like any other struct array: expose a[TableColumn]property, forward it to the table, and assign aslint.ListModelof columns.app.slint
main.py