Comments (2)
Indeed, all the reset function were having a problem. #4969 fixes it.
from slint.
Thanks @ogoffart.
Analogous behavior is triggered by custom filter model.
Here the example code:
// appwindow.slint
import { ListView, VerticalBox, Switch } from "std-widgets.slint";
export component AppWindow inherits Window {
in property <[int]> model;
in-out property only-evens <=> only-evens-switch.checked;
callback only-evens-changed <=> only-evens-switch.toggled;
VerticalBox {
only-evens-switch := Switch {
text: "Only evens";
}
ListView {
for item in root.model: Text {
text: item;
}
}
}
}
// main.cpp
#include <memory>
#include <utility>
#include "appwindow.h"
#include "slint.h"
class MyFilterModel: public slint::FilterModel<int>
{
bool onlyEvens{false};
[[nodiscard]] auto filter(const int& element) const -> bool { return !onlyEvens || element % 2 == 0; }
public:
MyFilterModel(std::shared_ptr<Model<int>> source_model):
slint::FilterModel<int>{std::move(source_model), [this](const int& element) { return filter(element); }}
{ }
[[nodiscard]] auto getOnlyEvens() const -> bool { return onlyEvens; }
void setOnlyEvens(bool value)
{
onlyEvens = value;
// Perform some kind of magic to force filtering re-evaluation
}
};
auto main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) -> int
{
auto appWindow{AppWindow::create()};
const auto model{std::make_shared<slint::VectorModel<int>>(std::vector<int>{1, 2, 3, 4, 5})};
const auto filterModel{std::make_shared<MyFilterModel>(model)};
appWindow->set_only_evens(filterModel->getOnlyEvens());
appWindow->set_model(filterModel);
appWindow->on_only_evens_changed([appWindow, filterModel]() {
filterModel->setOnlyEvens(appWindow->get_only_evens());
});
appWindow->run();
return 0;
}
Similar, calling FilterModel::reset()
triggers a call loop between FilterModel::reset()
and FilterModelInner::reset()
, that with my current toolchain ends with an exception in std::vector
implementation, after some iterations.
I don't know if a different issue should be filled for FilterModel
.
from slint.
Related Issues (20)
- No example in C++ documentation for SortModel, FilterModel, ...
- Android Build with JDK21 fails with java.lang.NullPointerException on SlintAndroidJavaHelper HOT 2
- TabWidget: Tab hover event not working when using Qt backend HOT 2
- Widgets react to all mouse buttons when using Qt backend HOT 1
- ListView items that are not visible are not focusable through tabbing. HOT 1
- `TouchArea`: `has-hover` does not make sense for touch events HOT 1
- Broken font rendering HOT 1
- slint is not working on dietpi OS on Raspberry pi 4 with 8GB RAM HOT 2
- [RFC] Text stroke/outline support HOT 3
- C++ filter model: defer first execution of filter function HOT 1
- In the novice tutorial, JS access to the slint array is not available. HOT 1
- StandardListView and StandardTableView always show scroll bars when using Qt backend HOT 2
- Misleading compilation error when default font cannot be embedded when embedding glyphs
- Checkbox does not show hover status when using Qt backend
- Combobox does not show hover status when using Qt backend
- Allow user to scroll through the tabs using the mouse wheel for Qt backend
- TabWidget tabbar overflows parent's dimensions
- Background color not updated on state change on MacOS
- Ruby/Golang bindings HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slint.