Replies: 5 comments 1 reply
-
It looks like you'll want to use To get the |
Beta Was this translation helpful? Give feedback.
-
Hi! I'm falling on this, would be nice be able to have some examples about how to this better. |
Beta Was this translation helpful? Give feedback.
-
I tried writing a minimal example project in Rust using Working with VecModel the backend code would be simiilar to this: let ui = App::create(); // instance to slint main window
let mut VecModel<VecModel<StandardListViewItem> model;
// I couldn't find a (simple) way to get a valid RC
let model_rc = ModelRc::new(model); // <--- This will return ModelRc<VecModel<StandardListViewItem>>
ui.set_rows_data_property(model_rc); // Then this fails The StandardTableView component is very limited and it is quite simple to replace it with a |
Beta Was this translation helpful? Give feedback.
-
Thank you @bjorn - here is a little example for import { StandardTableView, VerticalBox, Button } from "std-widgets.slint";
export component Example inherits Window {
preferred-height: 300px;
preferred-width: 300px;
in-out property <[[StandardListViewItem]]> table-data;
callback add-row();
VerticalBox {
table := StandardTableView {
columns: [
{ title: "Column 1" },
{ title: "Column 2" },
];
// NOTE: rows are managed by the backend
rows: table-data;
}
Button {
text: "Add row";
clicked => {
add-row();
}
}
}
} And the rust part use slint::{ModelRc, StandardListViewItem, VecModel};
use std::rc::Rc;
slint::include_modules!();
fn main() {
let ui = Example::new().unwrap();
let table_vec: Vec<ModelRc<StandardListViewItem>> = vec![];
let table_model = Rc::new(VecModel::from(table_vec));
ui.set_table_data(table_model.to_owned().into());
ui.on_add_row({
move || {
table_model.push(VecModel::from_slice(&[
StandardListViewItem::from("<new>"),
StandardListViewItem::from("<new>"),
]));
}
});
ui.run().unwrap();
} |
Beta Was this translation helpful? Give feedback.
-
Thx all! I'm new in the gui part, so at first I did not know Rc must be used to access the elements. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been trying add a row to a StandardTableView, though this applies to a StandardListView as well, basically trying to do the equivalent of a my_vector.push(new_row). Unfortunately, there doesn't seem to be a way to do it. Here's what I've come up with:
Elsewhere in my rust code
In my appwindow.slint code
Replacing the entire model seems to be the only way to add a row? This seems somewhat awkward.
Beta Was this translation helpful? Give feedback.
All reactions