Ejemplo n.º 1
0
    def editorEvent(self, event: QEvent, model: 'PropModel',
                    option: QStyleOptionViewItem, index: QModelIndex) -> bool:
        """
		Change the data in the model and the state of the checkbox
		if the user presses the left mouse button or presses
		Key_Space or Key_Select and this cell is editable. Otherwise do nothing.

		:param event: The event that will take place to trigger the editor Event.
		:type event: QEvent
		:param model: The model that our delegate will render.
		:type model: PropModel
		:param option: Option for the kind've event that takes place.
		:type option: QStyleOptionViewItem
		:param index: Index of the events.
		:type index: QModelIndex
		:return: true if the given editor is a valid QWidget and the given event is handled; otherwise returns false.
		:rtype: bool
		"""
        event.type()
        if not (index.flags() & QtCore.Qt.ItemIsEditable) > 0:
            return False

        data = index.internalPointer()
        if index.column() != 1 or not isinstance(
                data, Property) or data.getType() != bool:
            return QStyledItemDelegate.editorEvent(self, event, model, option,
                                                   index)

        if data.isReadOnly():
            return False

        # Do not change the checkbox-state
        if event.type() == QEvent.MouseButtonPress:
            return False
        if event.type() == QEvent.MouseButtonRelease or event.type(
        ) == QEvent.MouseButtonDblClick:
            if event.button(
            ) != QtCore.Qt.LeftButton or not self.getCheckBoxRect(
                    option).contains(event.pos()):
                return False
            if event.type() == QEvent.MouseButtonDblClick:
                return True
        elif event.type() == QEvent.KeyPress:
            if event.key() != QtCore.Qt.Key_Space and event.key(
            ) != QtCore.Qt.Key_Select:
                return False
        else:
            return False

        # Change the checkbox-state
        checkbox = QCheckBox('temp')
        checkbox.setChecked(not data.getValue())
        self.setModelData(checkbox, model, index)
        return True
Ejemplo n.º 2
0
 def editorEvent(self, event, model, option, index):
     if self._is_relationship_index(index):
         return super().editorEvent(event, model, option, index)
     return QStyledItemDelegate.editorEvent(self, event, model, option,
                                            index)
Ejemplo n.º 3
0
 def editorEvent(self, event, model, option, index):
     if self._is_scenario_alternative_index(index):
         return super().editorEvent(event, model, option, index)
     return QStyledItemDelegate.editorEvent(self, event, model, option,
                                            index)