views can respond to animated mouse clicks

This commit is contained in:
iLLiCiTiT 2020-10-04 09:48:20 +02:00
parent 79aa29cb7a
commit b547dffa41

View file

@ -83,6 +83,7 @@ class OverviewView(QtWidgets.QTreeView):
self.setHeaderHidden(True)
self.setRootIsDecorated(False)
self.setIndentation(0)
self.setAnimated(True)
def event(self, event):
if not event.type() == QtCore.QEvent.KeyPress:
@ -201,6 +202,34 @@ class InstanceView(OverviewView):
model.setData(index, new_state, QtCore.Qt.CheckStateRole)
self.toggled.emit(index, new_state)
def mousePressEvent(self, event):
if event.button() == QtCore.Qt.LeftButton:
pos_index = self.indexAt(event.pos())
if (
pos_index.isValid()
and pos_index.data(Roles.TypeRole) == model.InstanceType
):
if event.pos().x() < 20:
indexes = self.selectionModel().selectedIndexes()
if pos_index in indexes:
any_checked = False
for index in indexes:
if index.data(QtCore.Qt.CheckStateRole):
any_checked = True
break
for index in indexes:
self.toggled.emit(index, not any_checked)
return
else:
self.toggled.emit(pos_index, not any_checked)
elif event.pos().x() > self.width() - 20:
self.show_perspective.emit(pos_index)
return super(InstanceView, self).mousePressEvent(event)
def mouseReleaseEvent(self, event):
if event.button() == QtCore.Qt.LeftButton:
indexes = self.selectionModel().selectedIndexes()