how to synchronize navigation for two QTableView's...
Hello :)
I have two QTableViews with equal number of rows connected with two different QStandardItemModel's. I'd like to navigate by one QTableView - and get the same selection on the other one. Now I do the following:
Code:
connect (tabview1,
SIGNAL(pressed
(const QModelIndex &)), tabview2,
SLOT(setCurrentIndex
(const QModelIndex &)));
connect (tabview2,
SIGNAL(pressed
(const QModelIndex &)), tabview1,
SLOT(setCurrentIndex
(const QModelIndex &)));
While I use the mouse everything is all right but when i begin to move by means of keyboard - there is no reaction in the second QTableView...certainly :(
How could I get the desired result? Maybe there is any other signal to use?
Thanks in advance...
Re: how to synchronize navigation for two QTableView's...
You have to use the same selection model in both views, like this:
Code:
tabview2->setSelectionModel(tabview1->selectionModel());
You don't need those connect statements. And remember that "current item" and "selected item" are different entities.
Re: how to synchronize navigation for two QTableView's...
Thanks for answer. But I can't force it work :(
Code:
tabview1->setModel(Model1);
tabview2->setModel(Model2);
tabview1->setSelectionModel(tabview2->selectionModel());
No result at all... Surely I make something wrong.
Re: how to synchronize navigation for two QTableView's...
What do you mean by "no result"? What happens when you select an item in one of the views (I mean "select", so that its background changes)?
Re: how to synchronize navigation for two QTableView's...
Two views can share same selection model only if they have same model as well. I'm afraid you need custom slots which in a way or other map QModelIndex belonging to one model in a form which is known to the other model.
Re: how to synchronize navigation for two QTableView's...
Right. I missed that these are two different models.
Re: how to synchronize navigation for two QTableView's...
Quote:
What happens when you select an item in one of the views
Nothing happens :( The reason is that, probably
Quote:
Two views can share same selection model only if they have same model as well
Re: how to synchronize navigation for two QTableView's...
Maybe I can simply use any custom signal for work with keyboard events, analogous code in the first message? Before I use QTableWidget's and signal currentCellChanged(int,int,int,int) for this purpose but then some reasons appeares to replace these controls.
Re: how to synchronize navigation for two QTableView's...
Can't you just use the same model in both views? What do they contain?
Re: how to synchronize navigation for two QTableView's...
Unfortunately not. They contain different data. My purpose is just compare this data and find difference.
Re: how to synchronize navigation for two QTableView's...
In what way find the difference? Items that exist in one model but don't exist in the other or items that have different data in the same position? Either way you have to connect to the itemSelectionChanged() signal and compare the selection with the other model manually.
Re: how to synchronize navigation for two QTableView's...
All the comparisons have been made before, and these models just contain the flag of comparing result. I've noticed this defect at the last moment. :)
There is a decision - maybe not very good but it works!
A lot of thanks, everybody!
Re: how to synchronize navigation for two QTableView's...
Hi,
I would like to do something similar so I believe you can help me.
I have 4 treeview using the same QAbstractItemModel but different QSortProxyModel.
It is possible the share the selection between them?
I tried to use the same selection model for all of them by doing:
Code:
treeView2->setSelectionModel(selectionModel);
treeView3->setSelectionModel(selectionModel);
treeView4->setSelectionModel(selectionModel);
But I get the following error message when launching the application:
QAbstractItemView::setSelectionModel() failed: Trying to set a selection model, which works on a different model than the view.
I also tried to connect the tables selection models as shown in the previous post but nothing happens.
I could probably use a custom SLOT on itemSelectionChanged() SIGNAL and update the selection but I believe it would cycle?
Thanks for your help
Lionel