Is there any way to get a list of currently visible items in QAbstractItemView
? And, if it possible, to receive any notifications about changing of this list.
Upd:
I'm asking exactly about QAbstractItemView
or QTreeView
with non-plain structure, not QTableView
.
Upd2: I'm implementing tree view model with checkboxes. I want next behavior (same for checking/uncheking):
Check state are monitored/modified by external data source, so I need a mechanism to update all changed children/parents. dataChanged
signal is not enough for me because it is very expansive to build a list of all changed QModelIndex
for updating. And it is not necessary at all, because all fresh data will be picked from QAbstractItemModel::data
.
I found next dirty hack to update all items: emit dataChanged( QModelIndex(), QModelIndex() );
but it's undocumented for invalid indexes.
So, I need a way to force all visible items redraw they content with fresh data.
You can get the topleft and bottom right cell by calling:
tableview->indexAt(tableview->rect().topLeft())
tableview->indexAt(tableview->rect().bottomRight())
To get notification of change, reimplement the virtual function of qabstractscrollarea
scrollContentsBy
This function is called when the view port is scrolled. call QTableView::scrollContentsBy and then do whatever you need to.
For QTreeView
, the list of visible items can be traversed like this:
QTreeView& tv (yourTreeView);
// Get model index for first visible item
QModelIndex modelIndex = tv.indexAt(tv.rect().topLeft());
while (modelIndex.isValid())
{
// do something with the item indexed by modelIndex
...
// This navigates to the next visible item
modelIndex = tv.indexBelow(modelIndex);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With