本文整理汇总了Python中PyQt5.QtWidgets.QTreeWidget.findItems方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidget.findItems方法的具体用法?Python QTreeWidget.findItems怎么用?Python QTreeWidget.findItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTreeWidget
的用法示例。
在下文中一共展示了QTreeWidget.findItems方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ConfigurationWidget
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import findItems [as 别名]
#.........这里部分代码省略.........
page = pageData[2](self)
else:
mod = self.__importConfigurationPage(pageData[2])
if mod:
page = mod.create(self)
if page is not None:
self.configStack.addWidget(page)
pageData[-1] = page
try:
page.setMode(self.displayMode)
except AttributeError:
pass
return page
def showConfigurationPageByName(self, pageName, setCurrent=True):
"""
Public slot to show a named configuration page.
@param pageName name of the configuration page to show (string)
@param setCurrent flag indicating to set the current item (boolean)
"""
if pageName == "empty" or pageName not in self.configItems:
page = self.emptyPage
else:
pageData = self.configItems[pageName]
if pageData[-1] is None and pageData[2] is not None:
# the page was not loaded yet, create it
page = self.__initPage(pageData)
else:
page = pageData[-1]
if page is None:
page = self.emptyPage
elif setCurrent:
items = self.configList.findItems(
pageData[0],
Qt.MatchFixedString | Qt.MatchRecursive)
for item in items:
if item.data(0, Qt.UserRole) == pageName:
self.configList.setCurrentItem(item)
self.configStack.setCurrentWidget(page)
ssize = self.scrollArea.size()
if self.scrollArea.horizontalScrollBar():
ssize.setHeight(
ssize.height() -
self.scrollArea.horizontalScrollBar().height() - 2)
if self.scrollArea.verticalScrollBar():
ssize.setWidth(
ssize.width() -
self.scrollArea.verticalScrollBar().width() - 2)
psize = page.minimumSizeHint()
self.configStack.resize(max(ssize.width(), psize.width()),
max(ssize.height(), psize.height()))
if page != self.emptyPage:
page.polishPage()
self.buttonBox.button(QDialogButtonBox.Apply).setEnabled(True)
self.buttonBox.button(QDialogButtonBox.Reset).setEnabled(True)
else:
self.buttonBox.button(QDialogButtonBox.Apply).setEnabled(False)
self.buttonBox.button(QDialogButtonBox.Reset).setEnabled(False)
# reset scrollbars
for sb in [self.scrollArea.horizontalScrollBar(),
self.scrollArea.verticalScrollBar()]:
if sb:
sb.setValue(0)
示例2: MiscTab
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import findItems [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)