Important: Please read the Qt Code of Conduct -

Regarding position of hlighlighter in QTableWidget

  • Hello everyone,

    I am a newbie to Qt. I tried Googling for the problem, but I was not able to find it and hence posting here. If I have a 4x4 table and if I want to get the postion of highlighter in the table, what function should I use?? My expectation is that when the highlighter reaches the edge of the table (last row or last column), and when a button is pressed(say when the highlighter is at the last row and down button is pressed), I want to update the contents of the table. How to do this?? Please guide me in this regard.


  • Moderators


    You can use "currentRow": and "currentColumn": to get the row and column index of current item.
    So when you press the button get the currentRow and currentColumn and check if it matches with your requirement and then populate your tablewidget.

  • Hello,

    Thanks for your reply. So there is no inbuilt function which can detect when the end of table is reached??

    Thanks in advance,

  • Moderators


    AFAIK, there's no direct function which can detect it.
    There's a simple way, use the "currentCellChanged": signal and check if the focus is currently at the last item.
    For e.g
    void MainWindow::on_tableWidget_currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn)
    qDebug() << currentRow << currentColumn;
    if(currentRow==ui->tableWidget->rowCount()-1 && currentColumn==ui->tableWidget->columnCount()-1)
    qDebug() << "End of table reached";

    For this you need to connect currentCellChanged signal to the slot on_tableWidget_currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn)

Log in to reply