PDA

View Full Version : QTableWidget - how to place specific cell in top-left corner of viewport?



alketi
12th May 2013, 18:21
I'm using a QTableWidget and want to provide the ability to "zoom to the selected cells". This necessitates that, post-zoom, I put a specific cell in the top-left corner of the viewport.

The steps for this would be:



Allow the user to make a free selection of a range of cells
Resize all the cells, so that the selected geometry will exactly fill the available viewport size
Scroll the table so the top-left corner of the selection appears in the top-left corner of the viewport


The problem lies in step #3.

I'm using scrollToItem(), but this does not provide enough options to guarantee that the item will be scrolled to the top-left corner of the viewport. The only options available are PositionAtCenter, PositionAtBottom, PositionAtTop, EnsureVisible.

What is really needed is a PositionAtTopLeft.

The problem can be seen in the attached screenshots. I need cell #404 to be in the top-left corner.

Is there a way to place a specific cell in the top-left corner with QTableWidget?

9025
9026
9027

ChrisW67
12th May 2013, 21:17
Seems like you should be able to combine QTableView::columnViewportPosition() and rowViewportPortPosition() with scroll() to position the cell.