本文整理汇总了Python中PyQt5.Qt.QListWidget.item方法的典型用法代码示例。如果您正苦于以下问题:Python QListWidget.item方法的具体用法?Python QListWidget.item怎么用?Python QListWidget.item使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QListWidget
的用法示例。
在下文中一共展示了QListWidget.item方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ChoosePluginToolbarsDialog
# 需要导入模块: from PyQt5.Qt import QListWidget [as 别名]
# 或者: from PyQt5.Qt.QListWidget import item [as 别名]
class ChoosePluginToolbarsDialog(QDialog):
def __init__(self, parent, plugin, locations):
QDialog.__init__(self, parent)
self.locations = locations
self.setWindowTitle(
_('Add "%s" to toolbars or menus')%plugin.name)
self._layout = QVBoxLayout(self)
self.setLayout(self._layout)
self._header_label = QLabel(
_('Select the toolbars and/or menus to add <b>%s</b> to:') %
plugin.name)
self._layout.addWidget(self._header_label)
self._locations_list = QListWidget(self)
self._locations_list.setSelectionMode(QAbstractItemView.MultiSelection)
sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
self._locations_list.setSizePolicy(sizePolicy)
for key, text in locations:
self._locations_list.addItem(text)
if key in {'toolbar', 'toolbar-device'}:
self._locations_list.item(self._locations_list.count()-1
).setSelected(True)
self._layout.addWidget(self._locations_list)
self._footer_label = QLabel(
_('You can also customise the plugin locations '
'using <b>Preferences -> Customise the toolbar</b>'))
self._layout.addWidget(self._footer_label)
button_box = QDialogButtonBox(QDialogButtonBox.Ok |
QDialogButtonBox.Cancel)
button_box.accepted.connect(self.accept)
button_box.rejected.connect(self.reject)
self._layout.addWidget(button_box)
self.resize(self.sizeHint())
def selected_locations(self):
selected = []
for row in self._locations_list.selectionModel().selectedRows():
selected.append(self.locations[row.row()])
return selected
示例2: PluginWidget
# 需要导入模块: from PyQt5.Qt import QListWidget [as 别名]
# 或者: from PyQt5.Qt.QListWidget import item [as 别名]
class PluginWidget(QWidget):
TITLE = _('CSV/XML options')
HELP = _('Options specific to')+' CSV/XML '+_('output')
sync_enabled = False
formats = {'csv', 'xml'}
handles_scrolling = True
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.l = l = QVBoxLayout(self)
self.la = la = QLabel(_('Fields to include in output:'))
la.setWordWrap(True)
l.addWidget(la)
self.db_fields = QListWidget(self)
l.addWidget(self.db_fields)
self.la2 = la = QLabel(_('Drag and drop to re-arrange fields'))
l.addWidget(la)
self.db_fields.setDragEnabled(True)
self.db_fields.setDragDropMode(QListWidget.InternalMove)
self.db_fields.setDefaultDropAction(Qt.MoveAction)
self.db_fields.setAlternatingRowColors(True)
self.db_fields.setObjectName("db_fields")
def initialize(self, catalog_name, db):
self.name = catalog_name
from calibre.library.catalogs import FIELDS
db = get_gui().current_db
self.all_fields = {x for x in FIELDS if x != 'all'} | set(db.custom_field_keys())
sort_order, fields = get_saved_field_data(self.name, self.all_fields)
fm = db.field_metadata
def name(x):
if x == 'isbn':
return 'ISBN'
if x == 'library_name':
return _('Library name')
if x.endswith('_index'):
return name(x[:-len('_index')]) + ' ' + _('Number')
return fm[x].get('name') or x
def key(x):
return (sort_order.get(x, 10000), name(x))
self.db_fields.clear()
for x in sorted(self.all_fields, key=key):
QListWidgetItem(name(x) + ' (%s)' % x, self.db_fields).setData(Qt.UserRole, x)
if x.startswith('#') and fm[x]['datatype'] == 'series':
x += '_index'
QListWidgetItem(name(x) + ' (%s)' % x, self.db_fields).setData(Qt.UserRole, x)
# Restore the activated fields from last use
for x in range(self.db_fields.count()):
item = self.db_fields.item(x)
item.setCheckState(Qt.Checked if unicode_type(item.data(Qt.UserRole)) in fields else Qt.Unchecked)
def options(self):
# Save the currently activated fields
fields, all_fields = [], []
for x in range(self.db_fields.count()):
item = self.db_fields.item(x)
all_fields.append(unicode_type(item.data(Qt.UserRole)))
if item.checkState() == Qt.Checked:
fields.append(unicode_type(item.data(Qt.UserRole)))
set_saved_field_data(self.name, fields, {x:i for i, x in enumerate(all_fields)})
# Return a dictionary with current options for this widget
if len(fields):
return {'fields':fields}
else:
return {'fields':['all']}
示例3: PluginWidget
# 需要导入模块: from PyQt5.Qt import QListWidget [as 别名]
# 或者: from PyQt5.Qt.QListWidget import item [as 别名]
class PluginWidget(QWidget):
TITLE = _("CSV/XML Options")
HELP = _("Options specific to") + " CSV/XML " + _("output")
sync_enabled = False
formats = set(["csv", "xml"])
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.l = l = QVBoxLayout(self)
self.la = la = QLabel(_("Fields to include in output:"))
la.setWordWrap(True)
l.addWidget(la)
self.db_fields = QListWidget(self)
l.addWidget(self.db_fields)
self.la2 = la = QLabel(_("Drag and drop to re-arrange fields"))
l.addWidget(la)
self.db_fields.setDragEnabled(True)
self.db_fields.setDragDropMode(QListWidget.InternalMove)
self.db_fields.setDefaultDropAction(Qt.MoveAction)
self.db_fields.setAlternatingRowColors(True)
self.db_fields.setObjectName("db_fields")
def initialize(self, catalog_name, db):
self.name = catalog_name
from calibre.library.catalogs import FIELDS
db = get_gui().current_db
self.all_fields = {x for x in FIELDS if x != "all"} | set(db.custom_field_keys())
sort_order = gprefs.get(self.name + "_db_fields_sort_order", {})
fm = db.field_metadata
def name(x):
if x == "isbn":
return "ISBN"
if x == "library_name":
return _("Library Name")
if x.endswith("_index"):
return name(x[: -len("_index")]) + " " + _("Number")
return fm[x].get("name") or x
def key(x):
return (sort_order.get(x, 10000), name(x))
self.db_fields.clear()
for x in sorted(self.all_fields, key=key):
QListWidgetItem(name(x) + " (%s)" % x, self.db_fields).setData(Qt.UserRole, x)
if x.startswith("#") and fm[x]["datatype"] == "series":
x += "_index"
QListWidgetItem(name(x) + " (%s)" % x, self.db_fields).setData(Qt.UserRole, x)
# Restore the activated fields from last use
fields = frozenset(gprefs.get(self.name + "_db_fields", self.all_fields))
for x in range(self.db_fields.count()):
item = self.db_fields.item(x)
item.setCheckState(Qt.Checked if unicode(item.data(Qt.UserRole)) in fields else Qt.Unchecked)
def options(self):
# Save the currently activated fields
fields, all_fields = [], []
for x in xrange(self.db_fields.count()):
item = self.db_fields.item(x)
all_fields.append(unicode(item.data(Qt.UserRole)))
if item.checkState() == Qt.Checked:
fields.append(unicode(item.data(Qt.UserRole)))
gprefs.set(self.name + "_db_fields", fields)
gprefs.set(self.name + "_db_fields_sort_order", {x: i for i, x in enumerate(all_fields)})
# Return a dictionary with current options for this widget
if len(fields):
return {"fields": fields}
else:
return {"fields": ["all"]}
示例4: EventsQWidget
# 需要导入模块: from PyQt5.Qt import QListWidget [as 别名]
# 或者: from PyQt5.Qt.QListWidget import item [as 别名]
#.........这里部分代码省略.........
def send_datamanager_events(self):
"""
Add events stored in DataManager
"""
events = data_manager.get_events()
if events:
for event in events:
self.add_event(
event['event_type'],
event['message'],
timer=False,
host=event['host']
)
def add_event(self, event_type, msg, timer=False, host=None):
"""
Add event to events list
:param event_type: the type of event: OK, DOWN, ACK, ...
:type event_type: str
:param msg: message of event
:type msg: str
:param timer: timer to hide event at end of time
:type timer: bool
:param host: data of a host to set ``Qt.UserRole``
:type host: None | str
"""
if not self.event_exist(msg):
logger.debug(
'Add Event: msg: %s, timer: %s, host: %s', msg, timer, host
)
event = EventItem()
event.initialize(event_type, msg, timer=timer, host=host)
self.events_list.insertItem(0, event)
if timer:
event_duration = int(
settings.get_config('Alignak-app', 'notification_duration')
) * 1000
QTimer.singleShot(
event_duration,
lambda: self.remove_timer_event(event)
)
else:
logger.debug(
'Event with msg: %s already exist.', msg
)
def event_exist(self, msg):
"""
Check if event already displayed, move it to top and update tooltip.
Only for EventItem who have a ``Qt.UserRole``
:param msg: message of event
:type msg: str
:return: if message exist or not in events QWidgetList
:rtype: bool
"""
for i in range(0, self.events_list.count()):
if self.events_list.item(i).data(Qt.DisplayRole) == msg:
item = self.events_list.takeItem(i)
msg_to_send = '%s. (Send at %s)' % (msg, get_current_time())
item.setToolTip(msg_to_send)
self.events_list.insertItem(0, item)
return True
return False
def remove_timer_event(self, event):
"""
Remove EventItem with timer
:param event: EventItem with timer
:type event: EventItem
"""
logger.debug('Remove Timer Event: %s', event.text())
self.events_list.takeItem(self.events_list.row(event))
def remove_event(self, item=None):
"""
Remove item when user double click on an item
:param item: item to remove, else remove the current row
:type item: EventItem
"""
if isinstance(item, EventItem):
row = self.events_list.row(item)
self.events_list.takeItem(row)
else:
item = self.events_list.takeItem(self.events_list.currentRow())
logger.debug('Remove Event: %s', item.text())