一个 QStandardItemModel 用于不同的 QTableView、通用视图与特定视图

发布于 2024-09-16 10:25:05 字数 309 浏览 2 评论 0原文

我真的不知道这是否有意义,但这就是我想做的:

我正在 QT 中做我的游戏编辑器。目前我正在使用 QStandardItemModel 来存储我的所有场景项目。这些项目具有名称、位置、纹理(纹理向量,这是一个自定义类)、动画(动画向量)等。

我发现为行添加一个项目很有用,因为除了拥有它们之外,我还可以轻松添加或删除这些项目在一个地方,因此更改此模型应该会影响整个应用程序。

现在,我正在尝试对某个项目的“纹理”进行特定视图。这个 QTableView 应该显示纹理的名称、路径等。那么,基本上我如何获取通用模型中的纹理向量并填充另一个视图而不做另一个模型?

I really don't know if this makes sense but this is what I trying to do:

I'm doing my game's editor in QT. Currently I'm using a QStandardItemModel to store all my scene items. These items have names, position, Textures(vector of Texture which is a custom class), Animations (vector of Animation), etc.

I find it useful to have one item for row cause I can add or remove these items easily besides having them in a single place so changing this model should affect the entire app.

Now, I'm trying to do specific views for say the "Textures" of a certain item. This QTableView should show the texture's name, path etc. So, basically how can I grab the vector of Textures in the general model and fill another view without doing another model?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那支青花 2024-09-23 10:25:05

您将需要使用 QSortFilterProxy 模型。像这样设置一个。

QTableView *tableView = new QTableView;
MyItemModel *sourceModel = new MyItemModel(this);
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this);

proxyModel->setSourceModel(sourceModel);
proxyModel->setFilterKeyColumn(column_#_to_filter_by);
proxyModel->setFilterRegExp(a_regex_that_matches_the_item_you_want_to_display);
tableView->setModel(proxyModel);

您应该能够使用一种模型和不同的代理来设置不同的视图。

You will want to use a QSortFilterProxy Model. Set one up like this.

QTableView *tableView = new QTableView;
MyItemModel *sourceModel = new MyItemModel(this);
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this);

proxyModel->setSourceModel(sourceModel);
proxyModel->setFilterKeyColumn(column_#_to_filter_by);
proxyModel->setFilterRegExp(a_regex_that_matches_the_item_you_want_to_display);
tableView->setModel(proxyModel);

You should be able to use one model and different proxies to setup different views.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文