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. [Solved] Add new row to the QTableWidget to the top of the table?
QtWS25 Last Chance

[Solved] Add new row to the QTableWidget to the top of the table?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 8.7k Views
  • 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.
  • S Offline
    S Offline
    smithana
    wrote on 16 Sept 2014, 11:15 last edited by
    #1

    Hi,
    now I've got well working QTableWidget, but new rows are adding to the bootom of the table.
    The only way I found is to sort rows by SortItems function. But I havn't got column that I should base.
    This column is a number of the row, but it hasn't got an index.

    So can I add new row to the QTableWidget to the top of the table?

    Thanks!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      ashokb
      wrote on 16 Sept 2014, 11:26 last edited by
      #2

      bq.
      So can I add new row to the QTableWidget to the top of the table?

      "Top of the table" you mean at first position ?
      Then you can do this with

      @
      QTableWidget w;
      w.insertRow(0);
      @

      http://qt-project.org/doc/qt-4.8/qtablewidget.html#insertRow

      You don't need to sort rows for this!!

      1 Reply Last reply
      0
      • S Offline
        S Offline
        smithana
        wrote on 16 Sept 2014, 11:34 last edited by
        #3

        Yes, you understand correctly.

        Ok, I'm already add the first row insertRow(0), the second insertRow(1), the third insertRow(2) and else.
        Or you mean that I should every row add with insertRow(0) and it won't reload, the old 0 row became 1 and the new row will be 0?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 16 Sept 2014, 11:57 last edited by
          #4

          Hi and welcome to devnet,

          Exactly, insertRow(0) means that you want a new row at position 0 so if there's already one there, it will be moved to 1, 1 to 2 etc...

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            smithana
            wrote on 16 Sept 2014, 12:10 last edited by
            #5

            oh, thank you!

            1 Reply Last reply
            0
            • A Offline
              A Offline
              ashokb
              wrote on 16 Sept 2014, 12:32 last edited by
              #6

              If you got your answer please edit your title and add "[Solved]" at its beginning.

              1 Reply Last reply
              0
              • E Offline
                E Offline
                EnriqueH73
                wrote on 10 Nov 2015, 16:50 last edited by
                #7

                Thanks, It took me a day to find this answer.

                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