Hi I am trying to drag and drop single rows internally by clicking on any item in the row. I can't seem to get this to work. I can make them sortable by making the HEADERS movable, but then I must click on the header to initiate the drag which is not desirable. Here is a working example:

Qt Code:
  1. import os, sys
  2. from PyQt4 import QtCore, QtGui, QtSql
  3.  
  4. def makeDB():
  5. import sqlite3
  6. db = sqlite3.connect("db.db")
  7. db.execute("create table if not exists table1 (value text, data text)")
  8.  
  9. query = "insert into table1 (value, data) values (?, ?)"
  10.  
  11. valueSet = (("day","today"),("time","noon"),("food","cheese"))
  12. for values in valueSet:
  13. db.execute(query, values)
  14. db.commit()
  15.  
  16. class TestApp(QtGui.QDialog):
  17. def __init__(self, model, parent = None):
  18. super(TestApp, self).__init__(parent)
  19. self.model = model
  20.  
  21. table = QtGui.QTableView()
  22. table.setModel(self.model)
  23. table.setSortingEnabled(True)
  24. table.setDropIndicatorShown(True)
  25. table.setAcceptDrops(True)
  26. table.setDragEnabled(True)
  27. table.setSelectionMode(QtGui.QTableView.SingleSelection)
  28. table.setSelectionBehavior(QtGui.QTableView.SelectRows)
  29. table.setDragDropMode(QtGui.QAbstractItemView.InternalMove)
  30. '''table.horizontalHeader().setMovable(True)
  31. table.horizontalHeader().setDragEnabled(True)
  32. table.horizontalHeader().setDragDropMode(QtGui.QAbstractItemView.InternalMove)
  33. table.verticalHeader().setMovable(True)
  34. table.verticalHeader().setDragEnabled(True)
  35. table.verticalHeader().setDragDropMode(QtGui.QAbstractItemView.InternalMove)
  36. '''
  37. layout = QtGui.QVBoxLayout(self)
  38. layout.addWidget(table)
  39.  
  40.  
  41. class myModel(QtSql.QSqlTableModel):
  42. def __init__(self, parent = None):
  43. super(myModel, self).__init__(parent)
  44. self.setEditStrategy(QtSql.QSqlTableModel.OnFieldChange)
  45.  
  46. self.setTable("table1")
  47. self.select()
  48.  
  49. if __name__ == "__main__":
  50. if not os.path.exists("db.db"):
  51. makeDB()
  52.  
  53. myDb = QtSql.QSqlDatabase.addDatabase("QSQLITE")
  54. myDb.setDatabaseName("db.db")
  55. model = myModel()
  56.  
  57. app = QtGui.QApplication(sys.argv)
  58. dl = TestApp(model)
  59. dl.exec_()
To copy to clipboard, switch view to plain text mode