Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    How to know which row of the QTableWidget has the focus

    General and Desktop
    3
    12
    7872
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • I
      Indrajeet last edited by

      Hi All

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

      1 Reply Last reply Reply Quote 0
      • G
        goetz last edited by

        Is
        @
        tableWidget->currentRow()
        @
        what you're searching for?

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply Reply Quote 0
        • I
          Indrajeet last edited by

          Hi Volker

          How to do the same in case of QTableView.

          1 Reply Last reply Reply Quote 0
          • A
            andre last edited by

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

            1 Reply Last reply Reply Quote 0
            • I
              Indrajeet last edited by

              Hi Andre

              I did it like this & is working fine

              QTableView::currentIndex().row();

              1 Reply Last reply Reply Quote 0
              • A
                andre last edited by

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

                1 Reply Last reply Reply Quote 0
                • G
                  goetz last edited by

                  Invalid indexes return -1 for row and column.

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply Reply Quote 0
                  • I
                    Indrajeet last edited by

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

                    1 Reply Last reply Reply Quote 0
                    • I
                      Indrajeet last edited by

                      HI All

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

                      1 Reply Last reply Reply Quote 0
                      • G
                        goetz last edited by

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

                        @
                        ui->tableWidget->horizontalHeader()->hide();
                        ui->tableWidget->verticalHeader()->show();
                        @

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

                        !/doc/qt-4.7/images/qtableview-resized.png!

                        http://www.catb.org/~esr/faqs/smart-questions.html

                        1 Reply Last reply Reply Quote 0
                        • I
                          Indrajeet last edited by

                          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.

                          1 Reply Last reply Reply Quote 0
                          • A
                            andre last edited by

                            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.

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post