I'm implementing a QTableWidget in my Qt app (version Qt 4.8).
This QTableWidget is made of 18 QTableWidgetItems
When the user wants to change the current selected cell, it just calls:
tblWdgList->setCurrentCell(newCell, 0, QItemSelectionModel::ClearAndSelect);
The thing is that I want to put a small arrow at the same y-coordinate as the current selected cell. So I'm using the currentCellChanged signal.
connect(tblWdgList, SIGNAL(currentCellChanged(int,int,int,int)), this, SLOT(onCurrentCellChanged(int,int,int,int)));
When this currentCellChanged signal is emitted, it calls:
void CAppWdgSettingsLanguage::onCurrentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn)
{
Q_UNUSED(currentColumn)
Q_UNUSED(previousColumn)
lblArrow->move(lblArrow->pos().x(), tblWdgList->y() + tblWdgList->rowViewportPosition(currentRow));
}
This QTableWidget is in a dedicated page in my app, so that it is not always displayed.
When I open the page, it displays the QTableWidget and it should initialize the position of the arrow.
The problem is that the value returned by rowViewportPosition() during this initialization is wrong if the index of the current selected cell is over the number of cells that can be displayed when the vertical scroll bar is in up position.
This means that if I call the setCurrentCell method before the QTableWidget is displayed or just after it's displayed, rowViewportPosition() returns the y-coordinate regardless of the QTableWidget's geometry, as if there were no scrollbar. But if I delay the call of onCurrentCellChanged for about 200 ms for example (maybe to the minimum delay, just for testing purpose), then the rowViewportPosition() method returns the right value.
When you get the list of selected index: https://het.as.utexas.edu/HET/Software/html/qabstractitemview.html#selectedIndexes
You should be later be able to query the row: https://het.as.utexas.edu/HET/Software/html/qmodelindex.html (which should be the "y")