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?
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.
精彩评论