def editorEvent( self, event: QtCore.QEvent, model: QtCore.QAbstractItemModel, option: QStyleOptionViewItem, index: QtCore.QModelIndex, ) -> bool: if not (index.flags() & Qt.ItemIsEditable) != 0: return False if event.type() == QEvent.MouseButtonRelease or event.type( ) == QEvent.MouseButtonDblClick: if event.button() != Qt.LeftButton or not self.get_checkbox_rect( option).contains(event.pos()): return False if event.type() == QEvent.MouseButtonDblClick: return True elif event.type() == QEvent.KeyPress: if event.key() != Qt.Key_Space and event.key() != Qt.Key_Select: return False else: return False self.setModelData(None, model, index) return True
def edit(self, index: qc.QModelIndex, trigger, event) -> bool: if not (self.editTriggers() & trigger) or not index.isValid() or not ( index.flags() & (qc.Qt.ItemIsEditable | qc.Qt.ItemIsUserCheckable)): return False data = index.data(qc.Qt.EditRole) if isinstance(data, Event): self.actionProhibitionChanged.emit(True) dialog = EventChooserDialog(self, self.flow_data, enable_ctx_menu=False) dialog.show() self.chooserSelectSignal.connect(dialog.event_view.selectEvent) try: dialog.event_view.selectEvent( self.flow_data.flow.flowchart.events.index(data)) except ValueError: pass dialog.event_view.jumpToFlowchartRequested.connect( self.chooserEventDoubleClicked) dialog.finished.connect( lambda: self.actionProhibitionChanged.emit(False)) def onChooserAccept(): selected_event = dialog.getSelectedEvent() self.model().setData(index, selected_event, qc.Qt.EditRole) dialog.accepted.connect(onChooserAccept) return False return super().edit(index, trigger, event)
def editorEvent(self, event: QEvent, model: QAbstractItemModel, option: QStyleOptionViewItem, index: QModelIndex): if not int(index.flags() & Qt.ItemIsEditable) > 0: return False if event.type() == QEvent.MouseButtonPress and \ event.button() == Qt.LeftButton: self.setModelData(None, model, index) return True return False
def _abstract_item_view_edit(parent, model, index: qc.QModelIndex, trigger, triggers) -> bool: if not (triggers & trigger) or not index.isValid() or not ( index.flags() & (qc.Qt.ItemIsEditable | qc.Qt.ItemIsUserCheckable)): return False data = index.data(qc.Qt.UserRole) if isinstance(data, ActorIdentifier): dialog = ActorIdentifierEditDialog(parent, data) if dialog.exec_(): model.setData(index, dialog.identifier, qc.Qt.EditRole) return True if isinstance(data, list): array_dialog = ArrayEditDialog(parent, data) if array_dialog.exec_(): model.setData(index, array_dialog.data, qc.Qt.EditRole) return True return False
def editorEvent( self, event: QEvent, model: QAbstractItemModel, option: QStyleOptionViewItem, index: QModelIndex, ) -> bool: if not int(index.flags() & Qt.ItemIsEditable) > 0: return False if ( event.type() == QEvent.MouseButtonRelease and event.button() == Qt.LeftButton ): self.setModelData(None, model, index) return True elif event.type() == QEvent.KeyPress: if event.key() != Qt.Key_Space and event.key() != Qt.Key_Select: return False self.setModelData(None, model, index) return True return False
def paint( self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex ) -> None: """ Paint a checkbox without a label """ checked = index.data(Qt.CheckStateRole) == Qt.Checked enabled = int(index.flags() & Qt.ItemIsEditable) > 0 if not checked and not enabled: return painter.save() checkboxStyleOption = QStyleOptionButton() if checked: checkboxStyleOption.state |= QStyle.State_On else: checkboxStyleOption.state |= QStyle.State_Off if enabled: checkboxStyleOption.state |= QStyle.State_Enabled checkboxStyleOption.state &= ~QStyle.State_ReadOnly else: checkboxStyleOption.state &= ~QStyle.State_Enabled checkboxStyleOption.state |= QStyle.State_ReadOnly color = checkboxStyleOption.palette.color(QPalette.Window).darker(130) checkboxStyleOption.palette.setColor(QPalette.Text, color) checkboxStyleOption.rect = option.rect checkboxStyleOption.rect.setX( option.rect.x() + round(option.rect.width() / 2) - self.checkboxHalfWidth ) QApplication.style().drawControl( QStyle.CE_CheckBox, checkboxStyleOption, painter ) painter.restore()
def paint(self, painter: QtGui.QPainter, option: QStyleOptionViewItem, index: QtCore.QModelIndex) -> None: checked = bool(index.model().data(index, Qt.DisplayRole)) check_box_style_option = QStyleOptionButton() if (index.flags() & Qt.ItemIsEditable) != 0: check_box_style_option.state |= QStyle.State_Enabled else: check_box_style_option.state |= QStyle.State_ReadOnly if checked: check_box_style_option.state |= QStyle.State_On else: check_box_style_option.state |= QStyle.State_Off check_box_style_option.rect = self.get_checkbox_rect(option) # if not index.model().hasFlag(index, Qt.ItemIsEditable): # check_box_style_option.state |= QStyle.State_ReadOnly QApplication.style().drawControl(QStyle.CE_CheckBox, check_box_style_option, painter)
def updateActions(self, index: QModelIndex): super(AttrsTreeView, self).updateActions(index) # update edit action if index.flags() & Qt.ItemIsEditable: self.editAct.setEnabled(True) elif index.siblingAtColumn(VALUE_COLUMN).flags() & Qt.ItemIsEditable: valColIndex = index.siblingAtColumn(VALUE_COLUMN) self.setCurrentIndex(valColIndex) self.editAct.setEnabled(True) else: self.editAct.setEnabled(False) # update open actions indexIsLink = bool(index.data(IS_LINK_ROLE)) self.openInCurrTabAct.setEnabled(indexIsLink) self.openInBackgroundAct.setEnabled(indexIsLink) self.openInNewTabAct.setEnabled(indexIsLink) self.openInNewWindowAct.setEnabled(indexIsLink) self.openInCurrTabAct.setVisible(indexIsLink) self.openInBackgroundAct.setVisible(indexIsLink) self.openInNewTabAct.setVisible(indexIsLink) self.openInNewWindowAct.setVisible(indexIsLink)