我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用PyQt5.QtCore.Qt.ItemIsEnabled()。
def load_endpoints(self): self.choose_endpoint.endpoints.clear() for name in listdir(str(BASE_PATH / 'endpoints')): if name.endswith('.json'): item = QListWidgetItem(name.split('.json')[0], self.choose_endpoint.endpoints) item.setFlags(item.flags() & ~Qt.ItemIsEnabled) pb_msg_to_endpoints = defaultdict(list) with open(str(BASE_PATH / 'endpoints' / name)) as fd: for endpoint in load(fd, object_pairs_hook=OrderedDict): pb_msg_to_endpoints[endpoint['request']['proto_msg'].split('.')[-1]].append(endpoint) for pb_msg, endpoints in pb_msg_to_endpoints.items(): item = QListWidgetItem(' ' * 4 + pb_msg, self.choose_endpoint.endpoints) item.setFlags(item.flags() & ~Qt.ItemIsEnabled) for endpoint in endpoints: path_and_qs = '/' + endpoint['request']['url'].split('/', 3).pop() item = QListWidgetItem(' ' * 8 + path_and_qs, self.choose_endpoint.endpoints) item.setData(Qt.UserRole, endpoint) self.set_view(self.choose_endpoint)
def _makewidget(val, center=False): """ Small helper function that builds a TableWidgetItem and sets up the font the way we want""" out = QtWidgets.QTableWidgetItem(str(val)) out.setFlags(Qt.ItemIsEnabled) out.setFont(monospace) if(center): out.setTextAlignment(Qt.AlignCenter) return out
def keyPressEvent(self, event): if event.key() in [Qt.Key_Return, Qt.Key_Enter, Qt.Key_Space]:## Trigger Edit if (not self.m_editorPrivate.editedItem()): item = self.currentItem() if item: if (item.columnCount() >= 2 and ((item.flags() & (Qt.ItemIsEditable | Qt.ItemIsEnabled)) == (Qt.ItemIsEditable | Qt.ItemIsEnabled))): event.accept() ## If the current position is at column 0, move to 1. index = self.currentIndex() if (index.column() == 0): index = index.sibling(index.row(), 1) self.setCurrentIndex(index) self.edit(index) return super(QtPropertyEditorView, self).keyPressEvent(event)
def createIcons(self): configButton = QListWidgetItem(self.contentsWidget) configButton.setIcon(QIcon(':/images/config.png')) configButton.setText("Configuration") configButton.setTextAlignment(Qt.AlignHCenter) configButton.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) updateButton = QListWidgetItem(self.contentsWidget) updateButton.setIcon(QIcon(':/images/update.png')) updateButton.setText("Update") updateButton.setTextAlignment(Qt.AlignHCenter) updateButton.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) queryButton = QListWidgetItem(self.contentsWidget) queryButton.setIcon(QIcon(':/images/query.png')) queryButton.setText("Query") queryButton.setTextAlignment(Qt.AlignHCenter) queryButton.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.contentsWidget.currentItemChanged.connect(self.changePage)
def flags(self, index): col = index.column() flags = Qt.ItemIsEnabled if col == 0: flags = flags | Qt.ItemIsSelectable return flags
def flags(self, index): flags = Qt.ItemIsEnabled return flags
def set_row(self, row, model): for col, spec in enumerate(self.columns): value = spec.render(model) color = None if isinstance(value, tuple): value, color = value w = QTableWidgetItem(str(value)) if color is not None: w.setBackground(color) w.setTextAlignment(Qt.AlignVCenter | Qt.AlignLeft) w.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.setItem(row, col, w) self.setRowHidden(row, not self.apply_filter_to_row(row))
def disableItem(self, item): flags = item.flags() if (flags & Qt.ItemIsEnabled): flags &= ~Qt.ItemIsEnabled item.setFlags(flags) self.m_delegate.closeEditor(self.m_itemToIndex[item].property()) childCount = item.childCount() for i in range(childCount): child = item.child(i) self.disableItem(child)
def enableItem(self, item): flags = item.flags() flags |= Qt.ItemIsEnabled item.setFlags(flags) childCount = item.childCount() for i in range(childCount): child = item.child(i) property = self.m_itemToIndex[child].property() if property.isEnabled(): self.enableItem(child)
def updateItem(self, item): property = self.m_itemToIndex[item].property() expandIcon = QIcon() if (property.hasValue()): toolTip = property.toolTip() if len(toolTip) <= 0: toolTip = property.displayText() item.setToolTip(1, toolTip) item.setIcon(1, property.valueIcon()) if len(property.displayText())<=0: item.setText(1, property.valueText()) else: item.setText(1, property.displayText()) elif self.markPropertiesWithoutValue() and not self.m_treeWidget.rootIsDecorated(): expandIcon = self.m_expandIcon item.setIcon(0, expandIcon) item.setFirstColumnSpanned(not property.hasValue()) item.setToolTip(0, property.propertyName()) item.setStatusTip(0, property.statusTip()) item.setWhatsThis(0, property.whatsThis()) item.setText(0, property.propertyName()) wasEnabled = item.flags() & Qt.ItemIsEnabled isEnabled = wasEnabled if property.isEnabled(): parent = item.parent() if (not parent or (parent.flags() & Qt.ItemIsEnabled)): isEnabled = True else: isEnabled = False else: isEnabled = False if wasEnabled != isEnabled: if (isEnabled): self.enableItem(item) else: self.disableItem(item) self.m_treeWidget.viewport().update()
def mousePressEvent(self, event): super(QtPropertyEditorView, self).mousePressEvent(event) item = self.itemAt(event.pos()) if item: if ((item != self.m_editorPrivate.editedItem()) and (event.button() == Qt.LeftButton) and (self.header().logicalIndexAt(event.pos().x()) == 1) and ((item.flags() & (Qt.ItemIsEditable | Qt.ItemIsEnabled)) == (Qt.ItemIsEditable | Qt.ItemIsEnabled))): self.editItem(item, 1) elif (not self.m_editorPrivate.hasValue(item) and self.m_editorPrivate.markPropertiesWithoutValue() and not self.rootIsDecorated()): if (event.pos().x() + self.header().offset() < 20): item.setExpanded(not item.isExpanded()) ## ------------ QtPropertyEditorDelegate
def initCategories(self): generalButton = QListWidgetItem(self.categories) generalButton.setIcon(QIcon(':/images/settings-general.png')) generalButton.setText('General') generalButton.setToolTip('General settings') generalButton.setTextAlignment(Qt.AlignHCenter) generalButton.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) videoButton = QListWidgetItem(self.categories) videoButton.setIcon(QIcon(':/images/settings-video.png')) videoButton.setText('Video') videoButton.setToolTip('Video settings') videoButton.setTextAlignment(Qt.AlignHCenter) videoButton.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) themeButton = QListWidgetItem(self.categories) themeButton.setIcon(QIcon(':/images/settings-theme.png')) themeButton.setText('Theme') themeButton.setToolTip('Theme settings') themeButton.setTextAlignment(Qt.AlignHCenter) themeButton.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) logsButton = QListWidgetItem(self.categories) logsButton.setIcon(QIcon(':/images/settings-logs.png')) logsButton.setText('Logs') logsButton.setToolTip('Logging settings') logsButton.setTextAlignment(Qt.AlignHCenter) logsButton.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.categories.currentItemChanged.connect(self.changePage) self.categories.setCurrentRow(0) self.categories.setMaximumWidth(self.categories.sizeHintForColumn(0) + 2) self.setMinimumWidth(650 if sys.platform == 'darwin' else 620) if sys.platform != 'win32': self.adjustSize()
def update_table(self, emuchunks): ''' This function updates the table with new code objects received from the packager at the end of a "ripping" process. ''' if (not self.qtAvailable): return self._table.setRowCount(len(emuchunks)) self._table.emuchunks = emuchunks row = 0 for chunkName in emuchunks: nameField = QtWidgets.QTableWidgetItem(chunkName) nameField.setFlags(Qt.ItemIsEnabled) startAddr = QtWidgets.QTableWidgetItem('0x%.8x' % emuchunks[chunkName].startaddr) startAddr.setFlags(Qt.ItemIsEnabled) endAddr = QtWidgets.QTableWidgetItem('0x%.8x' % (int(emuchunks[chunkName].startaddr) + int(emuchunks[chunkName].codelen))) endAddr.setFlags(Qt.ItemIsEnabled) self._table.setItem(row, 0, nameField) self._table.setItem(row, 1, startAddr) self._table.setItem(row, 2, endAddr) row += 1 self._core.show() self._core.selectTab(self) self.show() ### Convenience wrappers for some frequently used things
def flags(self, index): return Qt.ItemIsEditable | Qt.ItemIsEnabled # if (index.column() == 0): # return Qt.ItemIsEditable | Qt.ItemIsEnabled # else: # return Qt.ItemIsEnabled
def flags(self, index): flags = Qt.ItemIsEnabled | Qt.ItemIsSelectable \ | Qt.ItemIsDragEnabled | Qt.ItemIsDropEnabled \ | Qt.ItemNeverHasChildren if not isinstance(self.data(index), (Font, Glyph)): flags |= Qt.ItemIsEditable return flags
def cb_function_selected(self, index): # get the peak number of the changed function i_peak = int(self.sender().objectName()[-1]) # check which function has been selected and update the table flags accordingly if index == 0: # peak has been turned off for i_row in range(1, 5): self.ui.table_widget.item(i_peak, i_row).setFlags(Qt.NoItemFlags) elif index == 1: # gaussian has been selected for i_row in range(1, 4): self.ui.table_widget.item(i_peak, i_row).setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable) self.ui.table_widget.item(i_peak, 4).setFlags(Qt.NoItemFlags) elif index == 2: # lorentzian has been selected for i_row in range(1, 3): self.ui.table_widget.item(i_peak, i_row).setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable) self.ui.table_widget.item(i_peak, 3).setFlags(Qt.NoItemFlags) self.ui.table_widget.item(i_peak, 4).setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable) elif index == 3: # voigt has been selected for i_row in range(1, 5): self.ui.table_widget.item(i_peak, i_row).setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable)
def flags(self, index): """Return the active flags for the given index. Add editable flag to items in the first colum or greater. """ activeFlags = (Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsUserCheckable) node = self.getNode(index) column = index.column() if column > 0 and not node.childCount(): activeFlags = activeFlags | Qt.ItemIsEditable return activeFlags
def _process_row(self, y, row): cols = self.columnCount() for x, i in enumerate(range(0, len(row), self._width)): block = row[i:i+self._width] item = QTableWidgetItem(codecs.encode(block, 'hex').decode()) item.setBackground(QBrush(QColor('lightgray'))) item.setForeground(QBrush(QColor('black'))) item.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter) item.setData(Qt.UserRole, block) # store original data if self._read_only: item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) else: item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable) self.setItem(y, x, item) # process remaining, unfilled cells for j in range(x+1, cols): item = QTableWidgetItem() item.setBackground(QBrush(QColor('white'))) item.setFlags(Qt.NoItemFlags) item.setTextAlignment(Qt.AlignHCenter) self.setItem(y, j, item) text = self._bytes_to_ascii(row) item = QTableWidgetItem(text) item.setData(Qt.UserRole, row) # store original data item.setTextAlignment(Qt.AlignLeft| Qt.AlignVCenter) item.setBackground(QBrush(QColor('lightblue'))) item.setForeground(QBrush(QColor('black'))) if self._read_only: item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) else: item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable) self.setItem(y, cols - 1, item)
def flags(self, index): if not index.isValid(): return Qt.NoItemFlags return Qt.ItemIsEnabled | Qt.ItemIsSelectable
def setupItemsTable(self): self.itemsTable = QTableWidget(len(self.items), 2) for row, item in enumerate(self.items): name = QTableWidgetItem(item) name.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) self.itemsTable.setItem(row, 0, name) quantity = QTableWidgetItem('1') self.itemsTable.setItem(row, 1, quantity)
def updateFormatsTable(self, mimeData=None): self.formatsTable.setRowCount(0) if mimeData is None: return for format in mimeData.formats(): formatItem = QTableWidgetItem(format) formatItem.setFlags(Qt.ItemIsEnabled) formatItem.setTextAlignment(Qt.AlignTop | Qt.AlignLeft) if format == 'text/plain': text = mimeData.text().strip() elif format == 'text/html': text = mimeData.html().strip() elif format == 'text/uri-list': text = " ".join([url.toString() for url in mimeData.urls()]) else: text = " ".join(["%02X" % ord(datum) for datum in mimeData.data(format)]) row = self.formatsTable.rowCount() self.formatsTable.insertRow(row) self.formatsTable.setItem(row, 0, QTableWidgetItem(format)) self.formatsTable.setItem(row, 1, QTableWidgetItem(text)) self.formatsTable.resizeColumnToContents(0)
def flags(self, QModelIndex): """ ?? ????? ?? ?? """ return Qt.ItemIsEditable | Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsTristate
def test_edit_rules(self): num_rules = len(self.message_type.ruleset) self.assertEqual(num_rules, self.dialog.ruleset_table_model.rowCount()) self.dialog.ui.rbAssignAutomatically.click() self.assertFalse(self.message_type.assign_manually) self.dialog.ui.rbAssignManually.click() self.assertTrue(self.message_type.assign_manually) self.dialog.ui.rbAssignAutomatically.click() self.assertTrue(self.dialog.ui.btnAddRule.isEnabled()) self.dialog.ui.btnAddRule.click() self.assertEqual(num_rules + 1, len(self.message_type.ruleset)) self.assertEqual(num_rules + 1, self.dialog.ruleset_table_model.rowCount()) model = self.dialog.ruleset_table_model model.setData(model.index(0, 0), 10, role=Qt.EditRole) self.assertEqual(self.message_type.ruleset[0].start, 9) model.setData(model.index(0, 1), 20, role=Qt.EditRole) self.assertEqual(self.message_type.ruleset[0].end, 20) model.setData(model.index(0, 2), 2, role=Qt.EditRole) self.assertEqual(self.message_type.ruleset[0].value_type, 2) model.setData(model.index(0, 3), 2, role=Qt.EditRole) model.setData(model.index(0, 4), "10101", role=Qt.EditRole) self.assertEqual(self.message_type.ruleset[0].target_value, "10101") for i in range(model.rowCount()): for j in range(model.columnCount()): self.assertEqual(model.flags(model.index(i, j)), Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable) self.dialog.ui.btnRemoveRule.click() self.assertEqual(num_rules, len(self.message_type.ruleset)) self.assertEqual(num_rules, self.dialog.ruleset_table_model.rowCount())
def flags(self, index): if not index.isValid(): return Qt.NoItemFlags try: _ = self.message_type[index.row()] except IndexError: return Qt.NoItemFlags return Qt.ItemIsEditable | Qt.ItemIsEnabled | Qt.ItemIsSelectable
def flags(self, index): return Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsUserCheckable
def flags(self, index: QModelIndex): if not index.isValid(): return Qt.ItemIsDropEnabled return Qt.ItemIsEditable | Qt.ItemIsEnabled | Qt.ItemIsSelectable | \ Qt.ItemIsUserCheckable | Qt.ItemIsDragEnabled | Qt.ItemIsDropEnabled
def flags(self, index): flags = Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsEditable try: lbl = self.labels[index.row()] except IndexError: return flags if len(lbl.fuzz_values) > 1: flags |= Qt.ItemIsUserCheckable else: lbl.fuzz_me = False return flags
def flags(self, index): return Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | \ Qt.ItemIsEditable | Qt.ItemIsDragEnabled
def flags(self, index: QModelIndex): if not index.isValid(): return Qt.ItemIsEnabled return Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled | Qt.ItemIsDropEnabled
def flags(self, index: QModelIndex): if not index.isValid(): return Qt.ItemIsEnabled return Qt.ItemIsEnabled | Qt.ItemIsDropEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled | Qt.ItemIsEditable
def flags(self, index: QModelIndex): return Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable
def flags(self, index: QModelIndex): if index.isValid(): if self.is_writeable: return Qt.ItemIsEnabled | Qt.ItemIsEditable | Qt.ItemIsSelectable else: return Qt.ItemIsEnabled | Qt.ItemIsSelectable else: return Qt.NoItemFlags
def flags(self, index: QModelIndex): if not index.isValid(): return Qt.NoItemFlags return Qt.ItemIsEditable | Qt.ItemIsEnabled | Qt.ItemIsSelectable
def flags(self, index): if not index.isValid(): return Qt.NoItemFlags try: _ = self.checksum_label.data_ranges[index.row()] except IndexError: return Qt.NoItemFlags return Qt.ItemIsEditable | Qt.ItemIsEnabled | Qt.ItemIsSelectable
def write_attribs(self): self.text = self.properties["<node_text>"].value if self.text.startswith("<designer.metadata.do.not.edit>"): self.getparent().model_item.takeRow(self.model_item.row()) else: self.model_item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsDragEnabled | Qt.ItemIsEnabled)
def init(self, name, tag, allowed_instances, sort_order="0", allowed_children=None, properties=None, wizard=None, required_children=None, either_children_group=None, at_least_one_children_group=None, name_editable=False, ): if not properties: properties = OrderedDict() if not allowed_children: allowed_children = () if not required_children: required_children = () if not either_children_group: either_children_group = () if not at_least_one_children_group: at_least_one_children_group = () self.name = name self.tag = tag self.sort_order = sort_order self.properties = properties self.allowed_children = allowed_children self.required_children = required_children self.either_children_group = either_children_group self.at_least_one_children_group = at_least_one_children_group self.hidden_children = [] self.is_hidden = False self.allowed_instances = allowed_instances self.wizard = wizard self.metadata = {} self.user_sort_order = "0".zfill(7) self.model_item = NodeStandardItem(self) self.model_item.setText(self.name) if allowed_instances > 1 or not allowed_instances: self.model_item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsDragEnabled | Qt.ItemIsEnabled | Qt.ItemIsEditable) else: self.model_item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsDropEnabled | Qt.ItemIsEnabled | Qt.ItemIsEditable) self.model_item.setEditable(name_editable)