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. Move rows in a QTableWidget
Forum Updated to NodeBB v4.3 + New Features

Move rows in a QTableWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.8k 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
    ivanicy
    wrote on 4 Jul 2018, 08:43 last edited by
    #1

    Hello!!

    I am trying to move rows in a QTableWidget. My idea is to have two buttons (up and down).

    The procedure that I want is:

    1. Select a row. (for example row 2)
    2. Push a button (for example, button down)
    3. The table must swap the row 2 with row 3, because we want to move the row 2 down.

    Is there any easy way to do this?

    Thank you very much!!

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 4 Jul 2018, 09:07 last edited by VRonin 7 Apr 2018, 09:13
      #2

      Unfortunately Qt generic models do not implement moveRows. You have 2 choices:

      • save the data, remove the row, insert the row and re-set the data
      • store temporary indexes in a user role and use QSortFilterProxyModel to sort it (requires switching to model+view and the change is not actually done in the original model)

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      6

      1/2

      4 Jul 2018, 08:43

      • Login

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