我们从Python开源项目中,提取了以下27个代码示例,用于说明如何使用PyQt5.QtCore.Qt.ItemIsSelectable()。
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 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 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 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 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 flags(self, QModelIndex): """ ?? ????? ?? ?? """ return Qt.ItemIsEditable | Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsTristate
def flags(self, QModelIndex): return Qt.ItemIsEditable | Qt.ItemIsSelectable | Qt.ItemIsEnabled
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): 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, QModelIndex): return Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsEditable
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 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)