本文整理汇总了Python中PyQt5.QtWidgets.QTreeWidget.editItem方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidget.editItem方法的具体用法?Python QTreeWidget.editItem怎么用?Python QTreeWidget.editItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTreeWidget
的用法示例。
在下文中一共展示了QTreeWidget.editItem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MiscTab
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import editItem [as 别名]
class MiscTab(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.name = self.tr("Misc")
self.markColorLabel = QLabel(self.tr("Default flag colors:"), self)
# TODO: enforce duplicate names avoidance
self.markColorWidget = QTreeWidget(self)
self.markColorWidget.setHeaderLabels(
(self.tr("Color"), self.tr("Name")))
self.markColorWidget.setRootIsDecorated(False)
self.markColorWidget.setSelectionBehavior(
QAbstractItemView.SelectRows)
# TODO: make this work correctly, top-level items only
# self.markColorWidget.setDragDropMode(QAbstractItemView.InternalMove)
self.addItemButton = QPushButton("+", self)
self.addItemButton.clicked.connect(self.addItem)
self.removeItemButton = QPushButton("−", self)
self.removeItemButton.clicked.connect(self.removeItem)
self.loadRecentFileBox = QCheckBox(
self.tr("Load most recent file on start"), self)
layout = QGridLayout(self)
l = 0
layout.addWidget(self.markColorLabel, l, 0, 1, 3)
l += 1
layout.addWidget(self.markColorWidget, l, 0, 1, 3)
l += 1
layout.addWidget(self.addItemButton, l, 0)
layout.addWidget(self.removeItemButton, l, 1)
l += 1
layout.addWidget(self.loadRecentFileBox, l, 0, 1, 3)
self.setLayout(layout)
self.readSettings()
def addItem(self):
def mangleNewName():
name = self.tr("New")
index = 0
while self.markColorWidget.findItems(name, Qt.MatchExactly, 1):
index += 1
name = "{0} ({1})".format(name, index)
return name
# TODO: not DRY with ctor
item = QTreeWidgetItem(self.markColorWidget)
item.setFlags(item.flags() | Qt.ItemIsEditable)
widget = ColorVignette(self)
widget.setColor(QColor(Qt.white))
widget.setMargins(2, 2, 2, 2)
widget.setMayClearColor(False)
self.markColorWidget.setItemWidget(item, 0, widget)
item.setText(1, mangleNewName())
self.markColorWidget.setCurrentItem(item)
self.markColorWidget.editItem(item, 1)
self.removeItemButton.setEnabled(True)
def removeItem(self):
i = self.markColorWidget.selectionModel().currentIndex().row()
self.markColorWidget.takeTopLevelItem(i)
if not self.markColorWidget.topLevelItemCount():
self.removeItemButton.setEnabled(False)
def readSettings(self):
entries = settings.readMarkColors()
for name, color in entries.items():
item = QTreeWidgetItem(self.markColorWidget)
item.setFlags(item.flags() | Qt.ItemIsEditable)
widget = ColorVignette(self)
widget.setColor(color)
widget.setMargins(2, 2, 2, 2)
widget.setMayClearColor(False)
self.markColorWidget.setItemWidget(item, 0, widget)
item.setText(1, name)
if not len(entries):
self.removeItemButton.setEnabled(False)
loadRecentFile = settings.loadRecentFile()
self.loadRecentFileBox.setChecked(loadRecentFile)
def writeSettings(self):
markColors = OrderedDict()
for i in range(self.markColorWidget.topLevelItemCount()):
item = self.markColorWidget.topLevelItem(i)
name = item.text(1)
color = self.markColorWidget.itemWidget(item, 0).color()
markColors[name] = color
settings.writeMarkColors(markColors)
loadRecentFile = self.loadRecentFileBox.isChecked()
settings.setLoadRecentFile(loadRecentFile)
示例2: EditorConfiguration
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import editItem [as 别名]
#.........这里部分代码省略.........
# End of line, Stop Scrolling At Last Line, Trailing space, Word wrap
vboxg6 = QVBoxLayout(group6)
vboxg6.setContentsMargins(5, 15, 5, 5)
self._checkEndOfLine = QCheckBox(
translations.TR_PREFERENCES_EDITOR_CONFIG_END_OF_LINE)
self._checkEndOfLine.setChecked(settings.USE_PLATFORM_END_OF_LINE)
vboxg6.addWidget(self._checkEndOfLine)
self._checkEndAtLastLine = QCheckBox(
translations.TR_PREFERENCES_EDITOR_CONFIG_END_AT_LAST_LINE)
self._checkEndAtLastLine.setChecked(settings.END_AT_LAST_LINE)
vboxg6.addWidget(self._checkEndAtLastLine)
self._checkTrailing = QCheckBox(
translations.TR_PREFERENCES_EDITOR_CONFIG_REMOVE_TRAILING)
self._checkTrailing.setChecked(settings.REMOVE_TRAILING_SPACES)
vboxg6.addWidget(self._checkTrailing)
self._allowWordWrap = QCheckBox(
translations.TR_PREFERENCES_EDITOR_CONFIG_WORD_WRAP)
self._allowWordWrap.setChecked(settings.ALLOW_WORD_WRAP)
vboxg6.addWidget(self._allowWordWrap)
formFeatures.addWidget(group6, 3, 1)
# pack all the groups
vbox.addWidget(container_widget_with_all_preferences)
vbox.addItem(QSpacerItem(0, 10, QSizePolicy.Expanding,
QSizePolicy.Expanding))
self._preferences.savePreferences.connect(self.save)
def _add_code_pep8(self):
item = QTreeWidgetItem()
item.setFlags(item.flags() | Qt.ItemIsEditable)
self._listIgnoreViolations.addTopLevelItem(item)
self._listIgnoreViolations.setCurrentItem(item)
self._listIgnoreViolations.editItem(item, 0)
def _remove_code_pep8(self):
index = self._listIgnoreViolations.indexOfTopLevelItem(
self._listIgnoreViolations.currentItem())
self._listIgnoreViolations.takeTopLevelItem(index)
def _enable_check_inline(self, val):
"""Method that takes a value to enable the inline style checking"""
if val == Qt.Checked:
self._checkStyle.setChecked(True)
def _enable_errors_inline(self, val):
"""Method that takes a value to enable the inline errors checking"""
if val == Qt.Checked:
self._checkErrors.setChecked(True)
def _disable_check_style(self, val):
"""Method that takes a value to disable the inline style checking"""
if val == Qt.Unchecked:
self._checkStyleOnLine.setChecked(False)
def _disable_show_errors(self, val):
"""Method that takes a value to disable the inline errors checking"""
if val == Qt.Unchecked:
self._showErrorsOnLine.setChecked(False)
def save(self):
"""Method to save settings"""
qsettings = IDE.ninja_settings()
settings.USE_TABS = bool(self._checkUseTabs.currentIndex())
qsettings.setValue('preferences/editor/useTabs',
settings.USE_TABS)