QT: internal drag and drop of rows in QTableView, that changes order of rows in QTableModel

后端 未结 1 1527
再見小時候
再見小時候 2021-01-13 18:46

I want to perform a sort of rows in QTableView, so that the underlying TableModel would have its data sorted, too: \"ent

相关标签:
1条回答
  • 2021-01-13 19:42

    You have several problems in your code I will address just two here:

    1. You are calling Model.moveRows with the wrong arguments:
      change self.model().moveRows(QModelIndex(), 0, 0, QModelIndex(), 1)
      by self.model().moveRows(QModelIndex(), 1, 1, QModelIndex(), 0)
    2. You are changing your data in the wrong way:
      change self.data = self.data[1] + self.data[0] + self.data[2]
      by self.data = [self.data[1], self.data[0] , self.data[2]]

    Note: problem 1 is the one who is provoking the exception on your code. Also note that is a bad idea naming an instance variable and a function the same (Model.data)

    0 讨论(0)
提交回复
热议问题