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:


  1. Allow the user to make a free selection of a range of cells
  2. Resize all the cells, so that the selected geometry will exactly fill the available viewport size
  3. 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?

Table_zoom1.jpg
Table_zoom2.jpg
Table_zoom3.jpg