def editorEvent(self, event: QtCore.QEvent, model: QtCore.QAbstractItemModel, option: 'QStyleOptionViewItem', index: QtCore.QModelIndex) -> bool: decorationRect = option.rect if event.type() == QEvent.MouseButtonPress: item = index.model().data(index, Qt.UserRole) if isinstance(item, QVariant): return QStyledItemDelegate.editorEvent(self, event, model, option, index) type = item['type'] value = item['value'] if type == 'device_activity': text_rect = calculate_text_rect( value['device'], font=ResourceLoader().qt_font_text_xs) if calculate_middle_rect(decorationRect, text_rect.width(), text_rect.height(), x=110, y=15).contains(event.pos()): print('点击了设备{device}'.format(device=value['device'])) return QStyledItemDelegate.editorEvent(self, event, model, option, index)
def editorEvent(self, event, model, option, index): value = QStyledItemDelegate.editorEvent(self, event, model, option, index) if value: if event.type() == QEvent.MouseButtonRelease: if index.data(Qt.CheckStateRole) == Qt.Checked: parent = index.parent() for i in range(model.rowCount(parent)): if i != index.row(): ix = parent.child(i, 0) model.setData(ix, Qt.Unchecked, Qt.CheckStateRole) return value
def editorEvent(self, event: QtCore.QEvent, model: QtCore.QAbstractItemModel, option: 'QStyleOptionViewItem', index: QtCore.QModelIndex) -> bool: decorationRect = option.rect if event.type() == QEvent.MouseButtonPress and calculate_middle_rect( decorationRect, 20, 20).contains(event.pos()): item = index.model().data(index, Qt.UserRole) if isinstance(item, QVariant): return QStyledItemDelegate.editorEvent(self, event, model, option, index) value = item['value'] type = item['type'] if type == 'checkbox': # 数据转换 value = 1 if value == 0 else 0 model.setData(index, value, Qt.DisplayRole) return QStyledItemDelegate.editorEvent(self, event, model, option, index)
def editorEvent(self, event, model, option, index): # We catch the mouse position in the widget to know which part to edit if type(event) == QMouseEvent: self.lastPos = event.pos() # - option.rect.topLeft() return QStyledItemDelegate.editorEvent(self, event, model, option, index)
def editorEvent(self, event, model, option, index): if event.type() == QEvent.MouseButtonRelease: if event.button() == Qt.LeftButton: variables.signals.open_dialog.emit(index.row()) return QStyledItemDelegate.editorEvent(self, event, model, option, index)