Created
December 26, 2015 13:20
-
-
Save iSplasher/8ebc42eaf9ea206b19bd to your computer and use it in GitHub Desktop.
Get currently visible QModelIndexes in QListView, QTableView or QTreeView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Put this in the class | |
def get_visible_indexes(self, column=0): | |
"find all galleries in viewport" | |
# used to find first index | |
gridW = self.W # width of single items | |
gridH = self.H # height of single items | |
region = self.viewport().visibleRegion() | |
idx_found = [] | |
def idx_is_visible(idx): | |
idx_rect = self.visualRect(idx) | |
return region.contains(idx_rect) or region.intersects(idx_rect) | |
#get first index | |
first_idx = self.indexAt(QPoint(gridW//2, 0)) # to get indexes on the way out of view | |
if not first_idx.isValid(): | |
first_idx = self.indexAt(QPoint(gridW//2, gridH//2)) | |
if first_idx.isValid(): | |
nxt_idx = first_idx | |
# now traverse items until index isn't visible | |
while(idx_is_visible(nxt_idx)): | |
idx_found.append(nxt_idx) | |
nxt_idx = nxt_idx.sibling(nxt_idx.row()+1, column) | |
return idx_found |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment