本文整理汇总了Python中PyQt4.Qt.QListWidgetItem类的典型用法代码示例。如果您正苦于以下问题:Python QListWidgetItem类的具体用法?Python QListWidgetItem怎么用?Python QListWidgetItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QListWidgetItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _addToTab
def _addToTab(self, submission, submissionURL, lst):
"""
Add a submission and its representative image to the lst under its tab.
:type submission: praw.objects.Submission
:type submissionURL: str
:type lst: QListWidget
"""
imagePath = submission.representativeImage
if imagePath is not None and imagePath.exists():
item = QListWidgetItem(submissionURL, lst)
item.setTextColor(Qt.transparent)
labelWidget = QLabel()
labelWidget.setOpenExternalLinks(True)
labelWidget.setTextFormat(Qt.RichText)
size = QSize(128, 158)
item.setSizeHint(size)
size = QSize(128, 128)
if imagePath.suffix == ".webm":
imagePath = pathlib.Path("RedditDataExtractor", "images", "videoImage.png").resolve()
pixmap = QPixmap(str(imagePath))
pixmap = pixmap.scaled(size, Qt.KeepAspectRatio)
height = pixmap.height()
width = pixmap.width()
submissionTitle = submissionURL[submissionURL[0:-1].rfind("/") + 1:-1]
labelWidget.setText(
'<a href="' + submissionURL + '"><img src="' + str(imagePath) + '" height="' + str(
height) + '" width="' + str(width) + '"><p>' + submissionTitle)
lst.setItemWidget(item, labelWidget)
示例2: refill_all_boxes
def refill_all_boxes(self):
if self.refilling:
return
self.refilling = True
self.current_device = None
self.current_format = None
self.clear_fields(new_boxes=True)
self.edit_format.clear()
self.edit_format.addItem('')
for format_ in self.current_plugboards:
self.edit_format.addItem(format_)
self.edit_format.setCurrentIndex(0)
self.edit_device.clear()
self.ok_button.setEnabled(False)
self.del_button.setEnabled(False)
self.existing_plugboards.clear()
for f in self.formats:
if f not in self.current_plugboards:
continue
for d in self.devices:
if d not in self.current_plugboards[f]:
continue
ops = []
for op in self.current_plugboards[f][d]:
ops.append('([' + op[0] + '] -> ' + op[1] + ')')
txt = '%s:%s = %s\n'%(f, d, ', '.join(ops))
item = QListWidgetItem(txt)
item.setData(Qt.UserRole, (f, d))
self.existing_plugboards.addItem(item)
self.refilling = False
示例3: _display_issues
def _display_issues(self):
self.values_list.clear()
issues = self.mm.get_all_issues(True)
for id, issue in issues:
item = QListWidgetItem(get_icon('images/books.png'), issue, self.values_list)
item.setData(1, (id,))
self.values_list.addItem(item)
示例4: link_stylesheets
def link_stylesheets(self, names):
s = self.categories['styles']
sheets = [unicode(s.child(i).data(0, NAME_ROLE).toString()) for i in xrange(s.childCount())]
if not sheets:
return error_dialog(self, _('No stylesheets'), _(
'This book currently has no stylesheets. You must first create a stylesheet'
' before linking it.'), show=True)
d = QDialog(self)
d.l = l = QVBoxLayout(d)
d.setLayout(l)
d.setWindowTitle(_('Choose stylesheets'))
d.la = la = QLabel(_('Choose the stylesheets to link. Drag and drop to re-arrange'))
la.setWordWrap(True)
l.addWidget(la)
d.s = s = QListWidget(d)
l.addWidget(s)
s.setDragEnabled(True)
s.setDropIndicatorShown(True)
s.setDragDropMode(self.InternalMove)
s.setAutoScroll(True)
s.setDefaultDropAction(Qt.MoveAction)
for name in sheets:
i = QListWidgetItem(name, s)
flags = Qt.ItemIsEnabled | Qt.ItemIsUserCheckable | Qt.ItemIsDragEnabled | Qt.ItemIsSelectable
i.setFlags(flags)
i.setCheckState(Qt.Checked)
d.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
bb.accepted.connect(d.accept), bb.rejected.connect(d.reject)
l.addWidget(bb)
if d.exec_() == d.Accepted:
sheets = [unicode(s.item(i).text()) for i in xrange(s.count()) if s.item(i).checkState() == Qt.Checked]
if sheets:
self.link_stylesheets_requested.emit(names, sheets)
示例5: __init__
def __init__(self, pathname, parent=None, watching=Purr.WATCHED):
self._pathname = pathname
pathname = Kittens.utils.collapseuser(pathname)
self._in_setWatching = True
QListWidgetItem.__init__(self, pathname, parent)
self.setFlags(Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled | Qt.ItemIsTristate)
self.setWatching(watching)
示例6: add_builtin_recipe
def add_builtin_recipe(self):
from calibre.web.feeds.recipes.collection import \
get_builtin_recipe_collection, get_builtin_recipe_by_id
from PyQt4.Qt import QDialog, QVBoxLayout, QListWidgetItem, \
QListWidget, QDialogButtonBox, QSize
d = QDialog(self)
d.l = QVBoxLayout()
d.setLayout(d.l)
d.list = QListWidget(d)
d.list.doubleClicked.connect(lambda x: d.accept())
d.l.addWidget(d.list)
d.bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel,
Qt.Horizontal, d)
d.bb.accepted.connect(d.accept)
d.bb.rejected.connect(d.reject)
d.l.addWidget(d.bb)
d.setWindowTitle(_('Choose builtin recipe'))
items = []
for r in get_builtin_recipe_collection():
id_ = r.get('id', '')
title = r.get('title', '')
lang = r.get('language', '')
if id_ and title:
items.append((title + ' [%s]'%lang, id_))
items.sort(key=lambda x:sort_key(x[0]))
for title, id_ in items:
item = QListWidgetItem(title)
item.setData(Qt.UserRole, id_)
d.list.addItem(item)
d.resize(QSize(450, 400))
ret = d.exec_()
d.list.doubleClicked.disconnect()
if ret != d.Accepted:
return
items = list(d.list.selectedItems())
if not items:
return
item = items[-1]
id_ = unicode(item.data(Qt.UserRole).toString())
title = unicode(item.data(Qt.DisplayRole).toString()).rpartition(' [')[0]
profile = get_builtin_recipe_by_id(id_, download_recipe=True)
if profile is None:
raise Exception('Something weird happened')
if self._model.has_title(title):
if question_dialog(self, _('Replace recipe?'),
_('A custom recipe named %s already exists. Do you want to '
'replace it?')%title):
self._model.replace_by_title(title, profile)
else:
return
else:
self.model.add(title, profile)
self.clear()
示例7: to_item
def to_item(key, ac, parent):
ic = ac.icon()
if not ic or ic.isNull():
ic = blank
ans = QListWidgetItem(ic, unicode(ac.text()).replace('&', ''), parent)
ans.setData(Qt.UserRole, key)
ans.setToolTip(ac.toolTip())
return ans
示例8: create_item
def create_item(self, data):
x = data
i = QListWidgetItem(
QIcon(QPixmap(x["path"]).scaled(256, 256, transformMode=Qt.SmoothTransformation)), x["name"], self.images
)
i.setData(Qt.UserRole, x["fname"])
i.setData(Qt.UserRole + 1, x["path"])
return i
示例9: _display_choices
def _display_choices(self):
self.values_list.clear()
choices = self.mm.search(self.mi.title)
if choices is None or len(choices)==0:
item = QListWidgetItem(get_icon('images/books.png'), _('there seem to be no matches'), self.values_list)
self.values_list.addItem(item)
for id, name in choices.items():
item = QListWidgetItem(get_icon('images/books.png'), name, self.values_list)
item.setData(1, (id,))
self.values_list.addItem(item)
示例10: add_account_to_list
def add_account_to_list(self, account):
at = self.app.preferences.ui.accountList
n = at.count()
icon = self.app.icons.get_service_icon(account.service, account.url)
li = QListWidgetItem( u"{0} ({1})".format(
account.name, account.service))
if icon is not None:
li.setIcon(icon)
at.insertItem(n, li)
at.setCurrentRow(n)
示例11: _display_formats
def _display_formats(self):
self.values_list.clear()
formats = self.dm.get_download_info(self.casanova_id)
if isinstance(formats, list):
for format in formats:
item = QListWidgetItem(get_icon('images/books.png'), format['type'], self.values_list)
item.setData(1, (format,))
self.values_list.addItem(item)
else:
return error_dialog(self.gui, 'Casanova message', unicode(formats), show=True)
示例12: build_dictionaries
def build_dictionaries(self, current=None):
self.dictionaries.clear()
for dic in sorted(dictionaries.all_user_dictionaries, key=lambda d:sort_key(d.name)):
i = QListWidgetItem(dic.name, self.dictionaries)
i.setData(Qt.UserRole, dic)
if dic.is_active:
i.setData(Qt.FontRole, self.emph_font)
if current == dic.name:
self.dictionaries.setCurrentItem(i)
if current is None and self.dictionaries.count() > 0:
self.dictionaries.setCurrentRow(0)
示例13: __init__
def __init__(self, parent, user):
if user.username == "root":
icon = "root"
name = _("Super User")
else:
name = user.username
icon = "normal"
label = "%s (%s)" % (name, user.realname)
QListWidgetItem.__init__(self, QIcon(":/gui/pics/user_%s.png" % icon), label, parent)
self.user = user
示例14: show_current_dictionary
def show_current_dictionary(self, *args):
d = self.current_dictionary
if d is None:
return
self.dlabel.setText(_('Configure the dictionary: <b>%s') % d.name)
self.is_active.blockSignals(True)
self.is_active.setChecked(d.is_active)
self.is_active.blockSignals(False)
self.words.clear()
for word, lang in sorted(d.words, key=lambda x:sort_key(x[0])):
i = QListWidgetItem('%s [%s]' % (word, get_language(lang)), self.words)
i.setData(Qt.UserRole, (word, lang))
示例15: init_input_order
def init_input_order(self, defaults=False):
if defaults:
input_map = prefs.defaults['input_format_order']
else:
input_map = prefs['input_format_order']
all_formats = set()
self.opt_input_order.clear()
for fmt in all_input_formats().union(set(['ZIP', 'RAR'])):
all_formats.add(fmt.upper())
for format in input_map + list(all_formats.difference(input_map)):
item = QListWidgetItem(format, self.opt_input_order)
item.setData(Qt.UserRole, QVariant(format))
item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)