本文整理汇总了Python中PyQt5.Qt.QListWidget.addItems方法的典型用法代码示例。如果您正苦于以下问题:Python QListWidget.addItems方法的具体用法?Python QListWidget.addItems怎么用?Python QListWidget.addItems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QListWidget
的用法示例。
在下文中一共展示了QListWidget.addItems方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: order_widget
# 需要导入模块: from PyQt5.Qt import QListWidget [as 别名]
# 或者: from PyQt5.Qt.QListWidget import addItems [as 别名]
def order_widget(self, name, prefs=None):
prefs = prefs or tprefs
widget = QListWidget(self)
widget.addItems(prefs.defaults[name])
widget.setDragEnabled(True)
widget.setDragDropMode(widget.InternalMove)
widget.viewport().setAcceptDrops(True)
widget.setDropIndicatorShown(True)
widget.indexesMoved.connect(self.emit_changed)
widget.setDefaultDropAction(Qt.MoveAction)
widget.setMovement(widget.Snap)
widget.setSpacing(5)
widget.defaults = prefs.defaults[name]
def getter(w):
return list(map(unicode, (w.item(i).text() for i in xrange(w.count()))))
def setter(w, val):
order_map = {x:i for i, x in enumerate(val)}
items = list(w.defaults)
limit = len(items)
items.sort(key=lambda x:order_map.get(x, limit))
w.clear()
for x in items:
i = QListWidgetItem(w)
i.setText(x)
i.setFlags(i.flags() | Qt.ItemIsDragEnabled)
return self(name, widget=widget, getter=getter, setter=setter, prefs=prefs)
示例2: SelectNames
# 需要导入模块: from PyQt5.Qt import QListWidget [as 别名]
# 或者: from PyQt5.Qt.QListWidget import addItems [as 别名]
class SelectNames(QDialog): # {{{
def __init__(self, names, txt, parent=None):
QDialog.__init__(self, parent)
self.l = l = QVBoxLayout(self)
self.setLayout(l)
self.la = la = QLabel(_('Create a Virtual Library based on %s') % txt)
l.addWidget(la)
self._names = QListWidget(self)
self._names.addItems(sorted(names, key=sort_key))
self._names.setSelectionMode(self._names.ExtendedSelection)
l.addWidget(self._names)
self._or = QRadioButton(_('Match any of the selected %s names')%txt)
self._and = QRadioButton(_('Match all of the selected %s names')%txt)
self._or.setChecked(True)
l.addWidget(self._or)
l.addWidget(self._and)
self.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.bb.accepted.connect(self.accept)
self.bb.rejected.connect(self.reject)
l.addWidget(self.bb)
self.resize(self.sizeHint())
@property
def names(self):
for item in self._names.selectedItems():
yield unicode(item.data(Qt.DisplayRole) or '')
@property
def match_type(self):
return ' and ' if self._and.isChecked() else ' or '
示例3: addItems
# 需要导入模块: from PyQt5.Qt import QListWidget [as 别名]
# 或者: from PyQt5.Qt.QListWidget import addItems [as 别名]
def addItems(self, *args):
try:
return QListWidget.addItems(self, *args)
finally:
self.mark_as_editable()