Scroll QTableWidget to a specific column

I have a bunch of data in a QTableWidget, and I would like to be able to scroll it to a specific column. I am currently using scrollToItem (self.item (0, col)). However, these are hardcodes of the row at 0. This causes problems if the user looks at row 100 and scrolls to a specific column, as it loses its vertical position in the table.

Is there a way to find which row the user is currently viewing inside QScrollArea that QTableWidget provides? If so, I could easily replace this default string with the correct one.

Perhaps there is another way to achieve this result with something like .ensureWidgetVisible ()? However, I'm not sure how to get the right widget that I would like to scroll or make visible.

+4
source share
1 answer

One way to do this is to get the row index of the first visible row, and then use this to find the first visible element in the column that you want to copy:

def scrollToColumn(self, column=0): visible = self.itemAt(0, 0) if visible is not None: self.scrollToItem(self.item(visible.row(), column)) 

Since the line of the element you are scrolling is already visible, the view should not scroll vertically (unless verticalScrollMode is ScrollPerPixel , and the element at the point (0, 0) not completely visible).

+3
source

Source: https://habr.com/ru/post/1395849/


All Articles