本文整理汇总了Python中PyQt5.QtWidgets.QTreeWidget.setSelectionBehavior方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidget.setSelectionBehavior方法的具体用法?Python QTreeWidget.setSelectionBehavior怎么用?Python QTreeWidget.setSelectionBehavior使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTreeWidget
的用法示例。
在下文中一共展示了QTreeWidget.setSelectionBehavior方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MiscTab
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setSelectionBehavior [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: CueListDialog
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setSelectionBehavior [as 别名]
class CueListDialog(QDialog):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.setMinimumSize(400, 300)
self._cues = []
self.list = QTreeWidget(self)
self.list.setSelectionMode(self.list.SingleSelection)
self.list.setSelectionBehavior(self.list.SelectRows)
self.list.setAlternatingRowColors(True)
self.list.setIndentation(0)
self.list.setHeaderLabels(['Index', 'Name'])
self.list.header().setSectionResizeMode(QHeaderView.Fixed)
self.list.header().setSectionResizeMode(1, QHeaderView.Stretch)
self.list.header().setStretchLastSection(False)
self.setLayout(QVBoxLayout())
self.layout().addWidget(self.list)
self.buttons = QDialogButtonBox(self)
self.buttons.addButton(QDialogButtonBox.Cancel)
self.buttons.addButton(QDialogButtonBox.Ok)
self.layout().addWidget(self.buttons)
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)
def add_cue(self, cue):
try:
item = QTreeWidgetItem()
item.setTextAlignment(0, Qt.AlignCenter)
for n, prop in enumerate(['index', 'name']):
item.setText(n, str(cue.properties().get(prop, 'Undefined')))
self._cues.append(cue)
self.list.addTopLevelItem(item)
except Exception:
pass
def add_cues(self, cues):
for cue in cues:
self.add_cue(cue)
def remove_cue(self, index):
self.list.takeTopLevelItem(index)
return self._cues.pop(index)
def reset(self):
self.list.clear()
self._cues.clear()
def selected_cues(self):
cues = []
for item in self.list.selectedItems():
index = self.list.indexOfTopLevelItem(item)
cues.append(self._cues[index])
return cues
示例3: InspectorWindow
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setSelectionBehavior [as 别名]
#.........这里部分代码省略.........
l += 1
transformLayout.addWidget(scaleButton, l, 0)
transformLayout.addWidget(scaleXLabel, l, 1)
transformLayout.addWidget(self.scaleXEdit, l, 2)
transformLayout.addWidget(scaleYLabel, l, 3)
transformLayout.addWidget(self.scaleYEdit, l, 4)
transformLayout.addWidget(scaleXYBox, l, 5)
transformGroup.setLayout(transformLayout)
l += 1
transformLayout.addWidget(rotateButton, l, 0)
transformLayout.addWidget(rotateLabel, l, 1)
transformLayout.addWidget(self.rotateEdit, l, 2)
transformGroup.setLayout(transformLayout)
l += 1
transformLayout.addWidget(skewButton, l, 0)
transformLayout.addWidget(skewXLabel, l, 1)
transformLayout.addWidget(self.skewXEdit, l, 2)
transformLayout.addWidget(skewYLabel, l, 3)
transformLayout.addWidget(self.skewYEdit, l, 4)
transformLayout.addWidget(skewXYBox, l, 5)
transformGroup.setLayout(transformLayout)
l += 1
transformLayout.addWidget(snapButton, l, 0)
transformLayout.addWidget(self.snapEdit, l, 2)
transformGroup.setLayout(transformLayout)
layerSetGroup = AccordionBox(self.tr("Layers"), self)
layerSetLayout = QVBoxLayout(self)
self.layerSetWidget = QTreeWidget(self)
self.layerSetWidget.setHeaderLabels(
(self.tr("Layer Name"), self.tr("Color")))
self.layerSetWidget.setRootIsDecorated(False)
self.layerSetWidget.setSelectionBehavior(QAbstractItemView.SelectRows)
# TODO: make this work correctly, top-level items only
# self.layerSetWidget.setDragDropMode(QAbstractItemView.InternalMove)
layerSetLayout.addWidget(self.layerSetWidget)
layerSetGroup.setLayout(layerSetLayout)
spacer = QWidget()
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
mainLayout = QVBoxLayout()
mainLayout.addWidget(glyphGroup)
mainLayout.addWidget(transformGroup)
mainLayout.addWidget(layerSetGroup)
mainLayout.addWidget(spacer)
self.setLayout(mainLayout)
self.resize(200, self.height())
# -------------
# Notifications
# -------------
def _unsubscribeFromGlyph(self):
glyph = self._glyph
if glyph is not None:
glyph.removeObserver(self, "Glyph.Changed")
def _subscribeToGlyph(self, glyph):
if glyph is not None:
glyph.addObserver(
self, "_updateGlyphAttributes", "Glyph.Changed")
def _unsubscribeFromFont(self):
示例4: CueListDialog
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setSelectionBehavior [as 别名]
class CueListDialog(QDialog):
def __init__(self, cues=None, properties=('index', 'name'), **kwargs):
super().__init__(**kwargs)
self.setMinimumSize(600, 400)
self._properties = list(properties)
self._cues = {}
self.list = QTreeWidget(self)
self.list.setSelectionMode(QTreeWidget.SingleSelection)
self.list.setSelectionBehavior(QTreeWidget.SelectRows)
self.list.setAlternatingRowColors(True)
self.list.setIndentation(0)
self.list.setHeaderLabels([prop.title() for prop in properties])
self.list.header().setSectionResizeMode(QHeaderView.Fixed)
self.list.header().setSectionResizeMode(1, QHeaderView.Stretch)
self.list.header().setStretchLastSection(False)
self.list.sortByColumn(0, Qt.AscendingOrder)
self.list.setSortingEnabled(True)
if cues is not None:
self.add_cues(cues)
self.setLayout(QVBoxLayout())
self.layout().addWidget(self.list)
self.buttons = QDialogButtonBox(self)
self.buttons.addButton(QDialogButtonBox.Cancel)
self.buttons.addButton(QDialogButtonBox.Ok)
self.layout().addWidget(self.buttons)
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)
def add_cue(self, cue):
item = QTreeWidgetItem()
item.setTextAlignment(0, Qt.AlignCenter)
for n, prop in enumerate(self._properties):
try:
item.setData(n, Qt.DisplayRole, getattr(cue, prop, 'Undefined'))
except Exception as e:
logging.exception('Cannot display {0} property'.format(prop), e,
dialog=False)
self._cues[cue] = item
item.setData(0, Qt.UserRole, cue)
self.list.addTopLevelItem(item)
def add_cues(self, cues):
self.list.setSortingEnabled(False)
for cue in cues:
self.add_cue(cue)
self.list.setSortingEnabled(True)
def remove_cue(self, cue):
index = self.list.indexOfTopLevelItem(self._cues.pop(cue))
self.list.takeTopLevelItem(index)
def reset(self):
self.list.clear()
self._cues.clear()
def selected_cues(self):
cues = []
for item in self.list.selectedItems():
cues.append(item.data(0, Qt.UserRole))
return cues