Important: Please read the Qt Code of Conduct -

How to know which row of the QTableWidget has the focus

  • Hi All

    How to know programatically which row of the table is currently having the focus.

  • Is
    what you're searching for?

  • Hi Volker

    How to do the same in case of QTableView.

  • You call QTableView::selectionModel(), and use the methods of the returned [[doc:QItemSelectionModel]]

  • Hi Andre

    I did it like this & is working fine


  • Just hope that currentIndex() returns a valid index then...

  • Invalid indexes return -1 for row and column.

  • Ya Volker you are right but for that i have put conditional checking.

  • HI All

    Is it possible to get row numbers created automatically on left side in QTableWidget.
    How to get it?

  • The vertical header is displayed by default. You can tweak it manually like this:


    If you do not provide other data, it is enumerated automatically, starting with 1, like in this screenshot of the Docs:


  • Hi volker

    Thanks for reply.

    I want to know how to retrive these Numbers[1,2,3...] and store in some variable in case of QTableView.

  • You are confusing the matter again. Are you using QTableView or QTableWidget?

    QTableWidget gives you accessor method to get the items representing the headers (if you set them, I'd think), while if you are using QTableView, you can use the model to find out the header contents as well. If you do just a little bit of searching in the documentation on a relevant term like "header" you will find them in no time flat.

    I am wondering though: what is your goal? Why do you need to store the contents of the headers in some variables? It doesn't seem to make too much sense.

Log in to reply