本文整理汇总了Python中PyQt5.Qt.QListWidget类的典型用法代码示例。如果您正苦于以下问题:Python QListWidget类的具体用法?Python QListWidget怎么用?Python QListWidget使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QListWidget类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, all_authors, parent):
QListWidget.__init__(self, parent)
self.setDragEnabled(True)
self.setSelectionMode(self.ExtendedSelection)
self.setDropIndicatorShown(True)
self.setDragDropMode(self.InternalMove)
self.setAlternatingRowColors(True)
self.d = ItemDelegate(all_authors, self)
self.d.edited.connect(self.edited, type=Qt.QueuedConnection)
self.setItemDelegate(self.d)
示例2: _init_controls
def _init_controls(self):
layout = QVBoxLayout(self)
self.setLayout(layout)
ml = QHBoxLayout()
layout.addLayout(ml, 1)
self.keys_list = QListWidget(self)
self.keys_list.setSelectionMode(QAbstractItemView.SingleSelection)
self.keys_list.setFixedWidth(150)
self.keys_list.setAlternatingRowColors(True)
ml.addWidget(self.keys_list)
self.value_text = QTextEdit(self)
self.value_text.setTabStopWidth(24)
self.value_text.setReadOnly(False)
ml.addWidget(self.value_text, 1)
button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
button_box.accepted.connect(self._apply_changes)
button_box.rejected.connect(self.reject)
self.clear_button = button_box.addButton('Clear', QDialogButtonBox.ResetRole)
self.clear_button.setIcon(get_icon('trash.png'))
self.clear_button.setToolTip('Clear all settings for this plugin')
self.clear_button.clicked.connect(self._clear_settings)
layout.addWidget(button_box)
示例3: __init__
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())
示例4: __init__
def __init__(self, window, msg, formats, show_open_with=False):
QDialog.__init__(self, window)
self.resize(507, 377)
self.setWindowIcon(QIcon(I("mimetypes/unknown.png")))
self.setWindowTitle(_('Choose Format'))
self.l = l = QVBoxLayout(self)
self.msg = QLabel(msg)
l.addWidget(self.msg)
self.formats = QListWidget(self)
self.formats.setIconSize(QSize(64, 64))
self.formats.activated[QModelIndex].connect(self.activated_slot)
l.addWidget(self.formats)
self.h = h = QHBoxLayout()
h.setContentsMargins(0, 0, 0, 0)
l.addLayout(h)
if show_open_with:
self.owb = QPushButton(_('&Open With...'), self)
h.addWidget(self.owb)
self.own = QMenu(self.owb.text())
self.owb.setMenu(self.own)
self.own.aboutToShow.connect(self.populate_open_with)
self.buttonBox = bb = QDialogButtonBox(self)
bb.setStandardButtons(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
bb.accepted.connect(self.accept), bb.rejected.connect(self.reject)
h.addStretch(10), h.addWidget(self.buttonBox)
for format in formats:
self.formats.addItem(QListWidgetItem(file_icon_provider().icon_from_ext(format.lower()),
format.upper()))
self._formats = formats
self.formats.setCurrentRow(0)
self._format = self.open_with_format = None
self.populate_open_with()
示例5: ChoosePluginToolbarsDialog
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
示例6: __init__
def __init__(self, parent=None):
super(ServicesQWidget, self).__init__(parent)
# Fields
self.services = None
self.services_tree_widget = QTreeWidget()
self.services_list_widget = QListWidget()
self.service_data_widget = ServiceDataQWidget()
self.services_dashboard = ServicesDashboardQWidget()
示例7: __init__
def __init__(self, parent=None):
QListWidget.__init__(self, parent)
self.setDragEnabled(True)
self.setDragDropMode(self.InternalMove)
self.setDefaultDropAction(Qt.MoveAction)
self.setAlternatingRowColors(True)
self.setStyleSheet('QListView::item { padding: 0.5ex }')
self.viewport().setAcceptDrops(True)
self.setDropIndicatorShown(True)
self.setContextMenuPolicy(Qt.ActionsContextMenu)
self.ac_edit = ac = QAction(QIcon(I('edit_input.png')), _('Edit this bookmark'), self)
self.addAction(ac)
self.ac_delete = ac = QAction(QIcon(I('trash.png')), _('Remove this bookmark'), self)
self.addAction(ac)
self.ac_sort = ac = QAction(_('Sort by name'), self)
self.addAction(ac)
self.ac_sort_pos = ac = QAction(_('Sort by position in book'), self)
self.addAction(ac)
示例8: change_builtin
def change_builtin(self):
d = QDialog(self)
lw = QListWidget(d)
for (trigger, syntaxes), snip in iteritems(builtin_snippets):
snip = copy.deepcopy(snip)
snip['trigger'], snip['syntaxes'] = trigger, syntaxes
i = QListWidgetItem(self.snip_to_text(snip), lw)
i.setData(Qt.UserRole, snip)
d.l = l = QVBoxLayout(d)
l.addWidget(QLabel(_('Choose the built-in snippet to modify:')))
l.addWidget(lw)
lw.itemDoubleClicked.connect(d.accept)
d.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
l.addWidget(bb)
bb.accepted.connect(d.accept), bb.rejected.connect(d.reject)
if d.exec_() == d.Accepted and lw.currentItem() is not None:
self.stack.setCurrentIndex(1)
self.edit_snip.apply_snip(lw.currentItem().data(Qt.UserRole), creating_snippet=True)
示例9: __init__
def __init__(self, parent, key_type_name, plugin_keys, create_key, keyfile_ext = u""):
QDialog.__init__(self,parent)
self.parent = parent
self.key_type_name = key_type_name
self.plugin_keys = plugin_keys
self.create_key = create_key
self.keyfile_ext = keyfile_ext
self.json_file = (keyfile_ext == u"k4i")
self.setWindowTitle("{0} {1}: Manage {2}s".format(PLUGIN_NAME, PLUGIN_VERSION, self.key_type_name))
# Start Qt Gui dialog layout
layout = QVBoxLayout(self)
self.setLayout(layout)
keys_group_box = QGroupBox(_(u"{0}s".format(self.key_type_name)), self)
layout.addWidget(keys_group_box)
keys_group_box_layout = QHBoxLayout()
keys_group_box.setLayout(keys_group_box_layout)
self.listy = QListWidget(self)
self.listy.setToolTip(u"{0}s that will be used to decrypt ebooks".format(self.key_type_name))
self.listy.setSelectionMode(QAbstractItemView.SingleSelection)
self.populate_list()
keys_group_box_layout.addWidget(self.listy)
button_layout = QVBoxLayout()
keys_group_box_layout.addLayout(button_layout)
self._add_key_button = QtGui.QToolButton(self)
self._add_key_button.setIcon(QIcon(I('plus.png')))
self._add_key_button.setToolTip(u"Create new {0}".format(self.key_type_name))
self._add_key_button.clicked.connect(self.add_key)
button_layout.addWidget(self._add_key_button)
self._delete_key_button = QtGui.QToolButton(self)
self._delete_key_button.setToolTip(_(u"Delete highlighted key"))
self._delete_key_button.setIcon(QIcon(I('list_remove.png')))
self._delete_key_button.clicked.connect(self.delete_key)
button_layout.addWidget(self._delete_key_button)
spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
button_layout.addItem(spacerItem)
layout.addSpacing(5)
migrate_layout = QHBoxLayout()
layout.addLayout(migrate_layout)
migrate_layout.addStretch()
self.button_box = QDialogButtonBox(QDialogButtonBox.Close)
self.button_box.rejected.connect(self.close)
migrate_layout.addWidget(self.button_box)
self.resize(self.sizeHint())
示例10: keyPressEvent
def keyPressEvent(self, ev):
if ev.key() in (Qt.Key_Enter, Qt.Key_Return):
i = self.currentItem()
if i is not None:
self.bookmark_activated.emit(i)
ev.accept()
return
if ev.key() in (Qt.Key_Delete, Qt.Key_Backspace):
i = self.currentItem()
if i is not None:
self.ac_delete.trigger()
ev.accept()
return
return QListWidget.keyPressEvent(self, ev)
示例11: __init__
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")
示例12: SelectNames
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 '
示例13: __init__
def __init__(self, gui, icon, do_user_config):
QDialog.__init__(self, gui)
self.gui = gui
self.do_user_config = do_user_config
self.db = gui.current_db
self.l = QVBoxLayout()
self.setLayout(self.l)
self.header = QLabel(prefs['searchinbookbrainz'])
self.l.addWidget(self.header)
self.img = QLabel()
pixmap = QPixmap("images/BBt.svg")
self.img.setPixmap(pixmap)
self.l.addWidget(self.img)
# QCol = QColor()
# QCol.setRed(220)
# QCol.setGreen(255)
# QCol.setBlue(240)
self.setWindowTitle('Calibre Book Brainz Integration')
self.setWindowIcon(icon)
self.search_space = QLineEdit()
self.selected_button = QPushButton('Use title from selected book', self)
self.selected_button.clicked.connect(self.exporttitlefromselected)
self.l.addWidget(self.selected_button)
self.search_space = QLineEdit()
self.l.addWidget(self.search_space)
self.listWidget = QListWidget()
self.l.addWidget(self.listWidget)
self.searchExecutionButton = QPushButton('Search', self)
self.searchExecutionButton.clicked.connect(self.search)
self.l.addWidget(self.searchExecutionButton)
self.aboutButton = QPushButton('About', self)
self.aboutButton.clicked.connect(self.about)
self.l.addWidget(self.aboutButton)
self.resize(400, 600)
self.search_space.setFocus()
示例14: setup_ui
def setup_ui(self):
from calibre.gui2.ui import get_gui
db = get_gui().current_db
self.l = l = QVBoxLayout(self)
b = self.bb.addButton(_('&Add search'), self.bb.ActionRole)
b.setIcon(QIcon(I('plus.png')))
b.clicked.connect(self.add_search)
b = self.bb.addButton(_('&Remove search'), self.bb.ActionRole)
b.setIcon(QIcon(I('minus.png')))
b.clicked.connect(self.del_search)
b = self.bb.addButton(_('&Edit search'), self.bb.ActionRole)
b.setIcon(QIcon(I('modified.png')))
b.clicked.connect(self.edit_search)
self.slist = QListWidget(self)
self.slist.setStyleSheet('QListView::item { padding: 3px }')
self.slist.activated.connect(self.edit_search)
self.slist.setAlternatingRowColors(True)
self.searches = {name: db.saved_search_lookup(name) for name in db.saved_search_names()}
self.populate_search_list()
if self.initial_search is not None and self.initial_search in self.searches:
self.select_search(self.initial_search)
elif self.searches:
self.slist.setCurrentRow(0)
self.slist.currentItemChanged.connect(self.current_index_changed)
l.addWidget(self.slist)
self.desc = la = QLabel('\xa0')
la.setWordWrap(True)
l.addWidget(la)
l.addWidget(self.bb)
self.current_index_changed(self.slist.currentItem())
self.setMinimumHeight(500)
self.setMinimumWidth(600)
示例15: _init_controls
def _init_controls(self):
layout = QVBoxLayout(self)
self.setLayout(layout)
ml = QHBoxLayout()
layout.addLayout(ml, 1)
self.keys_list = QListWidget(self)
self.keys_list.setSelectionMode(QAbstractItemView.SingleSelection)
self.keys_list.setFixedWidth(150)
self.keys_list.setAlternatingRowColors(True)
ml.addWidget(self.keys_list)
self.value_text = QTextEdit(self)
self.value_text.setTabStopWidth(24)
self.value_text.setReadOnly(True)
ml.addWidget(self.value_text, 1)
button_box = QDialogButtonBox(QDialogButtonBox.Ok)
button_box.accepted.connect(self.accept)
self.clear_button = button_box.addButton(_('Clear'), QDialogButtonBox.ResetRole)
self.clear_button.setIcon(get_icon('trash.png'))
self.clear_button.setToolTip(_('Clear all settings for this plugin'))
self.clear_button.clicked.connect(self._clear_settings)
if DEBUG:
self.edit_button = button_box.addButton(_('Edit'), QDialogButtonBox.ResetRole)
self.edit_button.setIcon(get_icon('edit_input.png'))
self.edit_button.setToolTip(_('Edit settings.'))
self.edit_button.clicked.connect(self._edit_settings)
self.save_button = button_box.addButton(_('Save'), QDialogButtonBox.ResetRole)
self.save_button.setIcon(get_icon('save.png'))
self.save_button.setToolTip(_('Save setting for this plugin'))
self.save_button.clicked.connect(self._save_settings)
self.save_button.setEnabled(False)
layout.addWidget(button_box)