def search_mousepress event Save mouse click point if event button QtC

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
def search_mousepress(event):
"Save mouse click point"
if event.button() == QtCore.Qt.LeftButton:
setattr(self.ui.search_view, 'dragstart', copy.copy(event.pos()))
return QtGui.QTreeView.mousePressEvent(self.ui.search_view, event)
self.ui.search_view.mousePressEvent = search_mousepress
def search_mousemove(event):
"Start drag if mouse moved move then 30 pixels left or right"
view = self.ui.search_view
if not event.buttons() & QtCore.Qt.LeftButton:
return QtGui.QTreeView.mouseMoveEvent(self.ui.search_view, event)
start = getattr(view, 'dragstart')
if abs(event.x() - start.x()) < 30:
view.scrollTo(view.indexAt(event.pos()))
self.ui.search_view.setSelection(QtCore.QRect(event.pos(), start), QtGui.QItemSelectionModel.Rows | QtGui.QItemSelectionModel.Select)
event.accept()
return
else:
return QtGui.QTreeView.mouseMoveEvent(self.ui.search_view, event)