Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Need to swap row in a QTableWidget
Forum Updated to NodeBB v4.3 + New Features

Need to swap row in a QTableWidget

Scheduled Pinned Locked Moved C++ Gurus
3 Posts 2 Posters 6.9k 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.
  • P Offline
    P Offline
    Paco
    wrote on last edited by
    #1

    Hi,

    I have some problems with the QTableWidget, I can take an Item with takeItem() method, but not for a widget.
    There is only cellWidget(). The problem is when I use setCellWidget(), I erase the old widget even if I take it using cellWidget().

    I think, the QTableWidget erases the object and I only can have the address so the object is distroyed.

    So if I copy a Widget in an other, the other is erased so I can't swap row.

    My question is, do you have any idea to swap rows ?
    I use it because I have "up" and "down" buttons to move the rows.

    Thank you.
    Best regards.

    Sorry for my english, it's not my native language.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vsorokin
      wrote on last edited by
      #2

      You need get model instance for your QTableWidget with method model().
      It has type QAbstractItemModel, see documentation of this class, it has methods for removing/inserting rows/columns.

      --
      Vasiliy

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Paco
        wrote on last edited by
        #3

        Thanks a lot, I use you model function to take the model, and I sort a column in this model. So the column represent the index and I just need to swap the index value in column and I use sort function.

        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