本文整理汇总了Python中PyQt4.Qt.QListWidget.insertItems方法的典型用法代码示例。如果您正苦于以下问题:Python QListWidget.insertItems方法的具体用法?Python QListWidget.insertItems怎么用?Python QListWidget.insertItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.Qt.QListWidget
的用法示例。
在下文中一共展示了QListWidget.insertItems方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SelectTagsDialog
# 需要导入模块: from PyQt4.Qt import QListWidget [as 别名]
# 或者: from PyQt4.Qt.QListWidget import insertItems [as 别名]
class SelectTagsDialog(QDialog):
def __init__(self, parent, modal=True, flags=Qt.WindowFlags(), caption="Select Tags", ok_button="Select"):
QDialog.__init__(self, parent, flags)
self.setModal(modal)
self.setWindowTitle(caption)
lo = QVBoxLayout(self)
lo.setMargin(10)
lo.setSpacing(5)
# tag selector
self.wtagsel = QListWidget(self)
lo.addWidget(self.wtagsel)
# self.wtagsel.setColumnMode(QListBox.FitToWidth)
self.wtagsel.setSelectionMode(QListWidget.MultiSelection)
QObject.connect(self.wtagsel, SIGNAL("itemSelectionChanged()"), self._check_tag)
# buttons
lo.addSpacing(10)
lo2 = QHBoxLayout()
lo.addLayout(lo2)
lo2.setContentsMargins(0, 0, 0, 0)
lo2.setMargin(5)
self.wokbtn = QPushButton(ok_button, self)
self.wokbtn.setMinimumWidth(128)
QObject.connect(self.wokbtn, SIGNAL("clicked()"), self.accept)
self.wokbtn.setEnabled(False)
cancelbtn = QPushButton("Cancel", self)
cancelbtn.setMinimumWidth(128)
QObject.connect(cancelbtn, SIGNAL("clicked()"), self.reject)
lo2.addWidget(self.wokbtn)
lo2.addStretch(1)
lo2.addWidget(cancelbtn)
self.setMinimumWidth(384)
self._tagnames = []
def setTags(self, tagnames):
self._tagnames = tagnames
self.wtagsel.clear()
self.wtagsel.insertItems(0, list(tagnames))
def _check_tag(self):
for i in range(len(self._tagnames)):
if self.wtagsel.item(i).isSelected():
self.wokbtn.setEnabled(True)
return
else:
self.wokbtn.setEnabled(False)
def getSelectedTags(self):
return [tag for i, tag in enumerate(self._tagnames) if self.wtagsel.item(i).isSelected()]
示例2: insertItems
# 需要导入模块: from PyQt4.Qt import QListWidget [as 别名]
# 或者: from PyQt4.Qt.QListWidget import insertItems [as 别名]
def insertItems(self, row, items, setAsDefault = True):
"""
Insert items of widget starting at <row>.
If <setAsDefault> is True, <items> become the default list of
items for this widget. "Restore Defaults" will reset
the list of items to <items>.
Note: <items> will always replace the list of current items
in the widget. <row> is ignored. This is considered a bug.
-- Mark 2007-06-04
"""
if row <> 0:
msg = "PM_ListWidget.insertItems(): <row> must be zero."\
"See docstring for details:"
print_compact_traceback(msg)
return
if setAsDefault:
self.setAsDefault = setAsDefault
self.defaultItems = items
self.clear()
QListWidget.insertItems(self, row, items)