Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to know which row of the QTableWidget has the focus
Forum Updated to NodeBB v4.3 + New Features

How to know which row of the QTableWidget has the focus

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 9.0k Views 1 Watching
  • 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 Offline
    I Offline
    Indrajeet
    wrote on last edited by
    #1

    Hi All

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

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

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

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

      1 Reply Last reply
      0
      • I Offline
        I Offline
        Indrajeet
        wrote on last edited by
        #3

        Hi Volker

        How to do the same in case of QTableView.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • I Offline
            I Offline
            Indrajeet
            wrote on last edited by
            #5

            Hi Andre

            I did it like this & is working fine

            QTableView::currentIndex().row();

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                Invalid indexes return -1 for row and column.

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

                1 Reply Last reply
                0
                • I Offline
                  I Offline
                  Indrajeet
                  wrote on last edited by
                  #8

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

                  1 Reply Last reply
                  0
                  • I Offline
                    I Offline
                    Indrajeet
                    wrote on last edited by
                    #9

                    HI All

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

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      goetz
                      wrote on last edited by
                      #10

                      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
                      0
                      • I Offline
                        I Offline
                        Indrajeet
                        wrote on last edited by
                        #11

                        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
                        0
                        • A Offline
                          A Offline
                          andre
                          wrote on last edited by
                          #12

                          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
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved