Python PyQt5.QtCore.Qt.EditRole() Examples
The following are 30
code examples of PyQt5.QtCore.Qt.EditRole().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
PyQt5.QtCore.Qt
, or try the search function
.
Example #1
Source File: ComboBoxDelegateQt.py From KStock with GNU General Public License v3.0 | 7 votes |
def setModelData(self, editor, model, index): ''' Set model data to current choice (if choice is a key, set data to its associated value). ''' try: choice = self.choices[editor.currentIndex()] if (type(choice) is tuple) and (len(choice) == 2): # choice is a (key, value) tuple. key, val = choice value = copy.deepcopy(val) # Deepcopy of val in case it is a complex object. else: # choice is a value. value = choice model.setData(index, value, Qt.EditRole) index.model().dataChanged.emit(index, index) # Tell model to update cell display. except: pass
Example #2
Source File: PushButtonDelegateQt.py From KStock with GNU General Public License v3.0 | 6 votes |
def editorEvent(self, event, model, option, index): ''' Handle mouse events in cell. On left button release in this cell, call model's setData() method, wherein the button clicked action should be handled. Currently, the value supplied to setData() is the button text, but this is arbitrary. ''' if event.button() == Qt.LeftButton: if event.type() == QEvent.MouseButtonPress: if option.rect.contains(event.pos()): self._isMousePressed = True return True elif event.type() == QEvent.MouseButtonRelease: self._isMousePressed = False if option.rect.contains(event.pos()): model.setData(index, self.text, Qt.EditRole) # Model should handle button click action in its setData() method. return True return False
Example #3
Source File: RulesetTableModel.py From urh with GNU General Public License v3.0 | 6 votes |
def setData(self, index: QModelIndex, value, role=None): if role == Qt.EditRole: i, j = index.row(), index.column() rule = self.ruleset[i] try: if j == 0: rule.start = int(value) - 1 elif j == 1: rule.end = int(value) if j == 2: rule.value_type = int(value) if j == 3: rule.operator_description = self.operator_descriptions[int(value)] if j == 4: rule.target_value = value except ValueError: return False return True
Example #4
Source File: tabmodel_z6.py From python101 with MIT License | 6 votes |
def data(self, index, rola=Qt.DisplayRole): """ WyĆwietlanie danych """ i = index.row() j = index.column() if rola == Qt.DisplayRole: return '{0}'.format(self.tabela[i][j]) elif rola == Qt.CheckStateRole and (j == 3 or j == 4): if self.tabela[i][j]: return Qt.Checked else: return Qt.Unchecked elif rola == Qt.EditRole and j == 1: return self.tabela[i][j] else: return QVariant()
Example #5
Source File: MessageTypeTableModel.py From urh with GNU General Public License v3.0 | 6 votes |
def data(self, index, role=Qt.DisplayRole): row = index.row() if not index.isValid() or row >= len(self.message_types): return message_type = self.message_types[row] if role == Qt.DisplayRole: if index.column() == 0: return message_type.name elif index.column() == 1: return "" elif role == Qt.CheckStateRole: if index.column() == 0: return message_type.show elif index.column() == 1: return None elif role == Qt.EditRole: if index.column() == 0: return message_type.name elif role == Qt.FontRole and index.column() == 0: font = QFont() font.setBold(index.row() in self.selected_message_type_indices) return font
Example #6
Source File: tabmodel_z5.py From python101 with MIT License | 6 votes |
def data(self, index, rola=Qt.DisplayRole): """ WyĆwietlanie danych """ i = index.row() j = index.column() if rola == Qt.DisplayRole: return '{0}'.format(self.tabela[i][j]) elif rola == Qt.CheckStateRole and (j == 3 or j == 4): if self.tabela[i][j]: return Qt.Checked else: return Qt.Unchecked elif rola == Qt.EditRole and j == 1: return self.tabela[i][j] else: return QVariant()
Example #7
Source File: sparrowtablewidgets.py From sparrow-wifi with GNU General Public License v3.0 | 6 votes |
def __lt__(self, other): if ( isinstance(other, QTableWidgetItem) ): try: my_value = int(self.data(Qt.EditRole)) except: # This will throw an exception if a channel is say "3+5" for multiple channels # Break it down and sort it on the first channel # cellData = str(self.data(Qt.EditRole)) firstChannel = cellData.split('+')[0] my_value = int(firstChannel) try: other_value = int(other.data(Qt.EditRole)) except: # This will throw an exception if a channel is say "3+5" for multiple channels # Break it down and sort it on the first channel # cellData = str(self.data(Qt.EditRole)) firstChannel = cellData.split('+')[0] other_value = int(firstChannel) return my_value < other_value return super(IntTableWidgetItem, self).__lt__(other)
Example #8
Source File: sparrowtablewidgets.py From sparrow-wifi with GNU General Public License v3.0 | 6 votes |
def __lt__(self, other): if ( isinstance(other, QTableWidgetItem) ): try: my_value = float(self.data(Qt.EditRole)) except: my_value = 0.0 try: other_value = float(other.data(Qt.EditRole)) except: other_value = 0.0 return my_value < other_value return super(FloatTableWidgetItem, self).__lt__(other) # ------------------ Table Sorting by Timestamp Class ------------------------------
Example #9
Source File: wallet_data_models.py From dash-masternode-tool with MIT License | 6 votes |
def data(self, index, role=None): if index.isValid(): data = index.internalPointer() col = index.column() if data: if role in (Qt.DisplayRole, Qt.EditRole): if col == 0: # if isinstance(data, Bip44AccountType): # return data.get_account_name() # else: # return f'/{data.address_index}: {data.address}' return data elif col == 1: b = data.balance if b: b = b/1e8 return b elif col == 2: b = data.received if b: b = b/1e8 return b return QVariant()
Example #10
Source File: qt.py From mint-amazon-tagger with GNU General Public License v3.0 | 6 votes |
def data(self, index, role): if not index.isValid(): return None if index.column() == 0: value = ('' if self.my_data[index.row()][index.column() + 1] else 'Skip') else: value = self.my_data[index.row()][index.column() + 1] if role == Qt.EditRole: return value elif role == Qt.DisplayRole: return value elif role == Qt.CheckStateRole: if index.column() == 0: return ( Qt.Checked if self.my_data[index.row()][index.column() + 1] else Qt.Unchecked)
Example #11
Source File: pytablemodel.py From ray-optics with BSD 3-Clause "New" or "Revised" License | 6 votes |
def data(self, index, role): root = self.get_root_object() if role == Qt.DisplayRole or role == Qt.EditRole: r = index.row() c = index.column() eval_str = ('root' + self.colEvalStr[c]).format(r) try: val = eval(eval_str) valStr = self.colFormats[c].format(val) return valStr except IndexError: return '' except TypeError: print('Data type error: ', eval_str, val) return '' else: return None
Example #12
Source File: shell_table_editor.py From mhw_armor_edit with The Unlicense | 6 votes |
def setData(self, index, value, role=None): if not index.isValid(): return False if role == Qt.EditRole: node = index.internalPointer() try: value = int(value) except (ValueError, TypeError): return False if index.column() == 1: node.capacity = value self.dataChanged.emit(index, index) return True elif index.column() == 2: node.recoil = value self.dataChanged.emit(index, index) return True elif index.column() == 3: node.reload = value return True self.dataChanged.emit(index, index) return False
Example #13
Source File: test_analysis_tab_GUI.py From urh with GNU General Public License v3.0 | 6 votes |
def test_label_tooltip(self): self.cfc.ui.cbProtoView.setCurrentIndex(0) self.cfc.add_protocol_label(0, 16, 2, 0, edit_label_name=False) model = self.cfc.label_value_model model.setData(model.index(0, 0), "test", Qt.EditRole) table_model = self.cfc.protocol_model for i in range(0, 16): self.assertEqual(table_model.data(table_model.index(2, i), Qt.ToolTipRole), "test", msg=str(i)) for i in range(17, 100): self.assertEqual(table_model.data(table_model.index(2, i), Qt.ToolTipRole), "", msg=str(i)) self.cfc.add_protocol_label(20, 24, 2, 0, edit_label_name=False) checksum_field_type = next(ft for ft in self.cfc.field_types if ft.function == FieldType.Function.CHECKSUM) model.setData(model.index(1, 0), checksum_field_type.caption, Qt.EditRole) for i in range(20, 24): self.assertIn("Expected", table_model.data(table_model.index(2, i), Qt.ToolTipRole)) for i in range(0, 20): self.assertNotIn("Expected", table_model.data(table_model.index(2, i), Qt.ToolTipRole))
Example #14
Source File: ObjList.py From KStock with GNU General Public License v3.0 | 6 votes |
def setData(self, index, value, role = Qt.EditRole): if not index.isValid(): return False obj = self.getObject(index) prop = self.getProperty(index) if (obj is None) or (prop is None): return None try: action = prop.get('action', None) if action is not None: if action == "button": getAttrRecursive(obj, prop['attr'])() # Call obj.attr() return True elif action == "fileDialog": pass # File loading handled via @property.setter obj.attr below. Otherwise just sets the file name text. if role == Qt.EditRole: if type(value) == QVariant: value = value.toPyObject() if (QT_VERSION_STR[0] == '4') and (type(value) == QString): value = str(value) setAttrRecursive(obj, prop['attr'], value) return True except: return False return False
Example #15
Source File: ObjList.py From KStock with GNU General Public License v3.0 | 6 votes |
def data(self, index, role = Qt.DisplayRole): if not index.isValid(): return None obj = self.getObject(index) prop = self.getProperty(index) if role == Qt.BackgroundRole: return color(obj.D) if role == Qt.TextAlignmentRole: return Qt.AlignCenter if (obj is None) or (prop is None): return None try: if role in [Qt.DisplayRole, Qt.EditRole]: return getAttrRecursive(obj, prop['attr']) except: return None return None
Example #16
Source File: LabelValueTableModel.py From urh with GNU General Public License v3.0 | 6 votes |
def setData(self, index: QModelIndex, value, role=None): row = index.row() lbl = self.display_labels[row] if role == Qt.EditRole and index.column() in (0, 1, 2, 3): if index.column() == 0: lbl.name = value new_field_type = self.controller.field_types_by_caption.get(value, None) self.controller.active_message_type.change_field_type_of_label(lbl, new_field_type) elif index.column() == 1: lbl.color_index = value self.label_color_changed.emit(lbl) elif index.column() == 2: lbl.display_format_index = value elif index.column() == 3: lbl.display_order_str = value self.dataChanged.emit(self.index(row, 0), self.index(row, self.columnCount())) elif role == Qt.CheckStateRole and index.column() == 0: lbl.show = value self.protolabel_visibility_changed.emit(lbl) return True
Example #17
Source File: weapon_editor.py From mhw_armor_edit with The Unlicense | 6 votes |
def data(self, qindex:QModelIndex, role=None): if role == Qt.DisplayRole or role == Qt.EditRole: entry = self.entries[qindex.row()] attr = self.columns[qindex.column()] value = getattr(entry, attr) if attr in ("gmd_name_index", "gmd_description_index"): return get_t9n(self.model, "t9n", value) elif attr == "kire_id": kire_model = self.model.get_relation_data("kire") if kire_model is None: return None else: return kire_model.entries[value] return value elif role == Qt.UserRole: entry = self.entries[qindex.row()] return entry
Example #18
Source File: FieldTypeTableModel.py From urh with GNU General Public License v3.0 | 6 votes |
def setData(self, index: QModelIndex, value, role=None): if role == Qt.EditRole: i, j = index.row(), index.column() fieldtype = self.field_types[i] try: if j == 0: present_captions = {ft.caption for ft in self.field_types} if value not in present_captions: fieldtype.caption = value elif j == 1: try: fieldtype.function = FieldType.Function[value] except KeyError: return False if j == 2: fieldtype.display_format_index = int(value) except ValueError: return False return True
Example #19
Source File: anchor_position_dialog.py From crazyflie-clients-python with GNU General Public License v2.0 | 6 votes |
def data(self, index, role=None): value = self._anchor_positions[index.row()][index.column()] if index.isValid(): if index.column() == 0: if role == Qt.CheckStateRole: return QVariant(value) elif index.column() == 1: if role == Qt.DisplayRole: return QVariant(value) else: if role == Qt.DisplayRole: return QVariant('%.2f' % (value)) elif role == Qt.EditRole: return QVariant(value) elif role == Qt.BackgroundRole: return self._get_background(index.row(), index.column()) return QVariant()
Example #20
Source File: test_project_manager.py From urh with GNU General Public License v3.0 | 5 votes |
def __set_label_name(self, index: int, name: str): model = self.form.compare_frame_controller.ui.tblLabelValues.model() model.setData(model.createIndex(index, 0), name, role=Qt.EditRole)
Example #21
Source File: FieldTypeTableModel.py From urh with GNU General Public License v3.0 | 5 votes |
def data(self, index: QModelIndex, role=Qt.DisplayRole): if not index.isValid(): return None if role == Qt.DisplayRole or role == Qt.EditRole: i = index.row() j = index.column() fieldtype = self.field_types[i] if j == 0: return fieldtype.caption elif j == 1: return fieldtype.function.name elif j == 2: return ProtocolLabel.DISPLAY_FORMATS[fieldtype.display_format_index]
Example #22
Source File: test_analysis_tab_GUI.py From urh with GNU General Public License v3.0 | 5 votes |
def test_label_value_table(self): table = self.cfc.ui.tblLabelValues # type: LabelValueTableView model = table.model() self.assertEqual(model.rowCount(), 0) self.cfc.add_protocol_label(45, 56, 0, 0, edit_label_name=False) self.assertEqual(model.rowCount(), 1) self.assertEqual(model.data(model.index(0, 2)), "Bit") self.assertEqual(model.data(model.index(0, 4)), "000011001110") model.setData(model.index(0, 2), 1, role=Qt.EditRole) self.assertEqual(model.data(model.index(0, 2)), "Hex") self.assertEqual(model.data(model.index(0, 4)), "0ce") model.setData(model.index(0, 2), 2, role=Qt.EditRole) self.assertEqual(model.data(model.index(0, 2)), "ASCII") model.setData(model.index(0, 2), 3, role=Qt.EditRole) self.assertEqual(model.data(model.index(0, 2)), "Decimal") self.assertEqual(model.data(model.index(0, 4)), "206") model.setData(model.index(0, 2), 4, role=Qt.EditRole) self.assertEqual(model.data(model.index(0, 2)), "BCD") self.assertEqual(model.data(model.index(0, 4)), "0??") self.assertIn("display type", model.data(model.index(0, 2), Qt.ToolTipRole)) self.assertIn("bit order", model.data(model.index(0, 3), Qt.ToolTipRole)) lbl = self.cfc.proto_analyzer.default_message_type[0] self.assertEqual(lbl.display_endianness, "big") model.setData(model.index(0, 3), "MSB/LE", role=Qt.EditRole) self.assertEqual(lbl.display_endianness, "little") model.setData(model.index(0, 3), "LSB/BE", role=Qt.EditRole) self.assertEqual(lbl.display_endianness, "big")
Example #23
Source File: tabmodel_z6.py From python101 with MIT License | 5 votes |
def setData(self, index, value, rola=Qt.DisplayRole): """ Zmiana danych """ i = index.row() j = index.column() if rola == Qt.EditRole and j == 1: self.tabela[i][j] = value elif rola == Qt.CheckStateRole and (j == 3 or j == 4): if value: self.tabela[i][j] = True else: self.tabela[i][j] = False return True
Example #24
Source File: ProtocolTreeModel.py From urh with GNU General Public License v3.0 | 5 votes |
def setData(self, index: QModelIndex, value, role=None): item = self.getItem(index) if role == Qt.EditRole and len(value) > 0: item.setData(value) return True elif role == Qt.CheckStateRole: item.show = value return True return False
Example #25
Source File: tabmodel_z5.py From python101 with MIT License | 5 votes |
def setData(self, index, value, rola=Qt.DisplayRole): """ Zmiana danych """ i = index.row() j = index.column() if rola == Qt.EditRole and j == 1: self.tabela[i][j] = value elif rola == Qt.CheckStateRole and (j == 3 or j == 4): if value: self.tabela[i][j] = True else: self.tabela[i][j] = False return True
Example #26
Source File: plotview.py From ray-optics with BSD 3-Clause "New" or "Revised" License | 5 votes |
def on_command_clicked(item): cntxt = item.data(qt.EditRole) fct, args, kwargs = cntxt fct(*args, **kwargs)
Example #27
Source File: plotview.py From ray-optics with BSD 3-Clause "New" or "Revised" License | 5 votes |
def setData(self, role, value): if role == qt.DisplayRole: self.txt = value return True elif role == qt.EditRole: self.cntxt = value return True else: return False
Example #28
Source File: plotview.py From ray-optics with BSD 3-Clause "New" or "Revised" License | 5 votes |
def data(self, role): if role == qt.DisplayRole: return self.txt elif role == qt.EditRole: return self.cntxt else: return None
Example #29
Source File: plotview.py From ray-optics with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, parent, txt, cntxt): super().__init__(parent) self.setData(qt.DisplayRole, txt) self.setData(qt.EditRole, cntxt)
Example #30
Source File: mpl_qtquick2.py From matplotlib_qtquick_playground with MIT License | 5 votes |
def setData(self, index, value, role=Qt.EditRole): if(index.row() < 0 or index.row() >= len(self._data_series)): return False series = self._data_series[index.row()] if role == self.SelectedRole: series._selected = not value self.dataChanged.emit(index, index, [role,]) return True return False