本文整理汇总了Python中PyQt5.Qt.QTreeWidget类的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidget类的具体用法?Python QTreeWidget怎么用?Python QTreeWidget使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTreeWidget类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, storage, show_files=False, item_func=browser_item):
QTreeWidget.__init__(self)
self.item_func = item_func
self.show_files = show_files
self.create_children(storage, self)
self.name = storage.name
self.object_id = storage.persistent_id
self.setMinimumHeight(350)
self.setHeaderHidden(True)
self.storage = storage
示例2: selectedIndexes
def selectedIndexes(self):
ans = QTreeWidget.selectedIndexes(self)
if self.ordered_selected_indexes:
# The reverse is needed because Qt's implementation of dropEvent
# reverses the selectedIndexes when dropping.
ans = list(sorted(ans, key=lambda idx:idx.row(), reverse=True))
return ans
示例3: __init__
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.l = l = QGridLayout(self)
self.toc_title = None
self.setLayout(l)
l.setContentsMargins(0, 0, 0, 0)
self.view = QTreeWidget(self)
self.delegate = Delegate(self.view)
self.view.setItemDelegate(self.delegate)
self.view.setHeaderHidden(True)
self.view.setAnimated(True)
self.view.setContextMenuPolicy(Qt.CustomContextMenu)
self.view.customContextMenuRequested.connect(self.show_context_menu, type=Qt.QueuedConnection)
self.view.itemActivated.connect(self.emit_navigate)
self.view.itemPressed.connect(self.item_pressed)
pi = plugins['progress_indicator'][0]
if hasattr(pi, 'set_no_activate_on_click'):
pi.set_no_activate_on_click(self.view)
self.view.itemDoubleClicked.connect(self.emit_navigate)
l.addWidget(self.view)
self.refresh_action = QAction(QIcon(I('view-refresh.png')), _('&Refresh'), self)
self.refresh_action.triggered.connect(self.refresh)
self.refresh_timer = t = QTimer(self)
t.setInterval(1000), t.setSingleShot(True)
t.timeout.connect(self.auto_refresh)
self.toc_name = None
self.currently_editing = None
示例4: __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()
示例5: __init__
def __init__(self, parent):
QTreeWidget.__init__(self, parent)
self.setHeaderLabel(_('Table of Contents'))
self.setIconSize(QSize(ICON_SIZE, ICON_SIZE))
self.setDragEnabled(True)
self.setSelectionMode(self.ExtendedSelection)
self.viewport().setAcceptDrops(True)
self.setDropIndicatorShown(True)
self.setDragDropMode(self.InternalMove)
self.setAutoScroll(True)
self.setAutoScrollMargin(ICON_SIZE*2)
self.setDefaultDropAction(Qt.MoveAction)
self.setAutoExpandDelay(1000)
self.setAnimated(True)
self.setMouseTracking(True)
self.in_drop_event = False
self.root = self.invisibleRootItem()
self.setContextMenuPolicy(Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.show_context_menu)
示例6: __init__
def __init__(self, parent=None):
QTreeWidget.__init__(self, parent)
self.categories = {}
self.ordered_selected_indexes = False
pi = plugins["progress_indicator"][0]
if hasattr(pi, "set_no_activate_on_click"):
pi.set_no_activate_on_click(self)
self.current_edited_name = None
self.delegate = ItemDelegate(self)
self.delegate.rename_requested.connect(self.rename_requested)
self.setTextElideMode(Qt.ElideMiddle)
self.setItemDelegate(self.delegate)
self.setIconSize(QSize(16, 16))
self.header().close()
self.setDragEnabled(True)
self.setEditTriggers(self.EditKeyPressed)
self.setSelectionMode(self.ExtendedSelection)
self.viewport().setAcceptDrops(True)
self.setDropIndicatorShown(True)
self.setDragDropMode(self.InternalMove)
self.setAutoScroll(True)
self.setAutoScrollMargin(TOP_ICON_SIZE * 2)
self.setDefaultDropAction(Qt.MoveAction)
self.setAutoExpandDelay(1000)
self.setAnimated(True)
self.setMouseTracking(True)
self.setContextMenuPolicy(Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.show_context_menu)
self.root = self.invisibleRootItem()
self.emblem_cache = {}
self.rendered_emblem_cache = {}
self.top_level_pixmap_cache = {
name: QPixmap(I(icon)).scaled(TOP_ICON_SIZE, TOP_ICON_SIZE, transformMode=Qt.SmoothTransformation)
for name, icon in {
"text": "keyboard-prefs.png",
"styles": "lookfeel.png",
"fonts": "font.png",
"misc": "mimetypes/dir.png",
"images": "view-image.png",
}.iteritems()
}
self.itemActivated.connect(self.item_double_clicked)
示例7: __init__
def __init__(self, parent = None):
super().__init__(parent)
self.tree = QTreeWidget()
self.tree.setHeaderHidden(True)
layout = QVBoxLayout()
layout.addWidget(self.tree)
self.setLayout(layout)
self.tree.setIndentation(0)
self.sections = []
self.section_dic = {}
self.define_sections()
self.add_sections()
示例8: keyPressEvent
def keyPressEvent(self, ev):
if ev.key() in (Qt.Key_Delete, Qt.Key_Backspace):
ev.accept()
self.request_delete()
else:
return QTreeWidget.keyPressEvent(self, ev)
示例9: commitData
def commitData(self, editor):
self.push_history()
return QTreeWidget.commitData(self, editor)
示例10: mimeData
def mimeData(self, indices):
ans = QTreeWidget.mimeData(self, indices)
names = (idx.data(0, NAME_ROLE) for idx in indices if idx.data(0, MIME_ROLE))
ans.setData(CONTAINER_DND_MIMETYPE, '\n'.join(filter(None, names)).encode('utf-8'))
return ans
示例11: mimeTypes
def mimeTypes(self):
ans = QTreeWidget.mimeTypes(self)
ans.append(CONTAINER_DND_MIMETYPE)
return ans
示例12: TOCViewer
class TOCViewer(QWidget):
navigate_requested = pyqtSignal(object, object)
refresh_requested = pyqtSignal()
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.l = l = QGridLayout(self)
self.toc_title = None
self.setLayout(l)
l.setContentsMargins(0, 0, 0, 0)
self.view = QTreeWidget(self)
self.delegate = Delegate(self.view)
self.view.setItemDelegate(self.delegate)
self.view.setHeaderHidden(True)
self.view.setAnimated(True)
self.view.setContextMenuPolicy(Qt.CustomContextMenu)
self.view.customContextMenuRequested.connect(self.show_context_menu, type=Qt.QueuedConnection)
self.view.itemActivated.connect(self.emit_navigate)
self.view.itemPressed.connect(self.item_pressed)
pi = plugins['progress_indicator'][0]
if hasattr(pi, 'set_no_activate_on_click'):
pi.set_no_activate_on_click(self.view)
self.view.itemDoubleClicked.connect(self.emit_navigate)
l.addWidget(self.view)
self.refresh_action = QAction(QIcon(I('view-refresh.png')), _('&Refresh'), self)
self.refresh_action.triggered.connect(self.refresh)
self.refresh_timer = t = QTimer(self)
t.setInterval(1000), t.setSingleShot(True)
t.timeout.connect(self.auto_refresh)
self.toc_name = None
self.currently_editing = None
def start_refresh_timer(self, name):
if self.isVisible() and self.toc_name == name:
self.refresh_timer.start()
def auto_refresh(self):
if self.isVisible():
try:
self.refresh()
except Exception:
# ignore errors during live refresh of the toc
import traceback
traceback.print_exc()
def refresh(self):
self.refresh_requested.emit() # Give boss a chance to commit dirty editors to the container
self.build()
def item_pressed(self, item):
if QApplication.mouseButtons() & Qt.LeftButton:
QTimer.singleShot(0, self.emit_navigate)
def show_context_menu(self, pos):
menu = QMenu(self)
menu.addAction(actions['edit-toc'])
menu.addAction(_('&Expand all'), self.view.expandAll)
menu.addAction(_('&Collapse all'), self.view.collapseAll)
menu.addAction(self.refresh_action)
menu.exec_(self.view.mapToGlobal(pos))
def iter_items(self, parent=None):
if parent is None:
parent = self.invisibleRootItem()
for i in range(parent.childCount()):
child = parent.child(i)
yield child
for gc in self.iter_items(parent=child):
yield gc
def emit_navigate(self, *args):
item = self.view.currentItem()
if item is not None:
dest = unicode_type(item.data(0, DEST_ROLE) or '')
frag = unicode_type(item.data(0, FRAG_ROLE) or '')
if not frag:
frag = TOP
self.navigate_requested.emit(dest, frag)
def build(self):
c = current_container()
if c is None:
return
toc = get_toc(c, verify_destinations=False)
self.toc_name = getattr(toc, 'toc_file_name', None)
self.toc_title = toc.toc_title
def process_node(toc, parent):
for child in toc:
node = QTreeWidgetItem(parent)
node.setText(0, child.title or '')
node.setData(0, DEST_ROLE, child.dest or '')
node.setData(0, FRAG_ROLE, child.frag or '')
tt = _('File: {0}\nAnchor: {1}').format(
child.dest or '', child.frag or _('Top of file'))
node.setData(0, Qt.ToolTipRole, tt)
process_node(child, node)
#.........这里部分代码省略.........
示例13: ServicesQWidget
class ServicesQWidget(QWidget):
"""
Class wo create services QWidget
"""
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()
def initialize(self):
"""
Initialize QWidget
"""
layout = QGridLayout()
self.setLayout(layout)
layout.setContentsMargins(0, 0, 0, 0)
# Services dashboard
self.services_dashboard.initialize()
for state in self.services_dashboard.states_btns:
self.services_dashboard.states_btns[state].clicked.connect(
lambda _, s=state: self.filter_services(state=s)
)
layout.addWidget(self.services_dashboard, 0, 0, 1, 2)
layout.addWidget(get_frame_separator(), 1, 0, 1, 2)
# Services QTreeWidget
self.services_tree_widget.setIconSize(QSize(32, 32))
self.services_tree_widget.setAlternatingRowColors(True)
self.services_tree_widget.header().close()
layout.addWidget(self.services_tree_widget, 2, 0, 1, 1)
# Services QListWidget
self.services_list_widget.clicked.connect(self.update_service_data)
self.services_list_widget.hide()
layout.addWidget(self.services_list_widget, 2, 0, 1, 1)
# Service DataWidget
self.service_data_widget.initialize()
layout.addWidget(self.service_data_widget, 2, 1, 1, 1)
def filter_services(self, state):
"""
Filter services with the wanted state
:param state: state of service: OK, WARNING, NOT_MONITORED, DOWNTIME
:return:
"""
# Clear QListWidget and update filter buttons of services dashboard
self.services_list_widget.clear()
for btn_state in self.services_dashboard.states_btns:
if btn_state != state:
self.services_dashboard.states_btns[btn_state].setChecked(False)
# Update QWidgets
if self.sender().isChecked():
self.set_filter_items(state)
self.services_tree_widget.hide()
self.services_list_widget.show()
else:
self.services_tree_widget.show()
self.services_list_widget.hide()
def set_filter_items(self, state):
"""
Add filter items to QListWidget corresponding to "state"
:param state: state of service to filter
:type state: str
"""
services_added = False
if state in 'NOT_MONITORED':
for service in self.services:
if not service.data['active_checks_enabled'] and \
not service.data['passive_checks_enabled']and \
not service.data['ls_downtimed'] and \
not service.data['ls_acknowledged']:
self.add_filter_item(service)
services_added = True
elif state in 'DOWNTIME':
for service in self.services:
if service.data['ls_downtimed']:
self.add_filter_item(service)
services_added = True
elif state in 'ACKNOWLEDGE':
for service in self.services:
if service.data['ls_acknowledged']:
self.add_filter_item(service)
services_added = True
else:
for service in self.services:
#.........这里部分代码省略.........
示例14: CheckLibraryDialog
class CheckLibraryDialog(QDialog):
def __init__(self, parent, db):
QDialog.__init__(self, parent)
self.db = db
self.setWindowTitle(_('Check Library -- Problems Found'))
self.setWindowIcon(QIcon(I('debug.png')))
self._tl = QHBoxLayout()
self.setLayout(self._tl)
self.splitter = QSplitter(self)
self.left = QWidget(self)
self.splitter.addWidget(self.left)
self.helpw = QTextEdit(self)
self.splitter.addWidget(self.helpw)
self._tl.addWidget(self.splitter)
self._layout = QVBoxLayout()
self.left.setLayout(self._layout)
self.helpw.setReadOnly(True)
self.helpw.setText(_('''\
<h1>Help</h1>
<p>calibre stores the list of your books and their metadata in a
database. The actual book files and covers are stored as normal
files in the calibre library folder. The database contains a list of the files
and covers belonging to each book entry. This tool checks that the
actual files in the library folder on your computer match the
information in the database.</p>
<p>The result of each type of check is shown to the left. The various
checks are:
</p>
<ul>
<li><b>Invalid titles</b>: These are files and folders appearing
in the library where books titles should, but that do not have the
correct form to be a book title.</li>
<li><b>Extra titles</b>: These are extra files in your calibre
library that appear to be correctly-formed titles, but have no corresponding
entries in the database</li>
<li><b>Invalid authors</b>: These are files appearing
in the library where only author folders should be.</li>
<li><b>Extra authors</b>: These are folders in the
calibre library that appear to be authors but that do not have entries
in the database</li>
<li><b>Missing book formats</b>: These are book formats that are in
the database but have no corresponding format file in the book's folder.
<li><b>Extra book formats</b>: These are book format files found in
the book's folder but not in the database.
<li><b>Unknown files in books</b>: These are extra files in the
folder of each book that do not correspond to a known format or cover
file.</li>
<li><b>Missing cover files</b>: These represent books that are marked
in the database as having covers but the actual cover files are
missing.</li>
<li><b>Cover files not in database</b>: These are books that have
cover files but are marked as not having covers in the database.</li>
<li><b>Folder raising exception</b>: These represent folders in the
calibre library that could not be processed/understood by this
tool.</li>
</ul>
<p>There are two kinds of automatic fixes possible: <i>Delete
marked</i> and <i>Fix marked</i>.</p>
<p><i>Delete marked</i> is used to remove extra files/folders/covers that
have no entries in the database. Check the box next to the item you want
to delete. Use with caution.</p>
<p><i>Fix marked</i> is applicable only to covers and missing formats
(the three lines marked 'fixable'). In the case of missing cover files,
checking the fixable box and pushing this button will tell calibre that
there is no cover for all of the books listed. Use this option if you
are not going to restore the covers from a backup. In the case of extra
cover files, checking the fixable box and pushing this button will tell
calibre that the cover files it found are correct for all the books
listed. Use this when you are not going to delete the file(s). In the
case of missing formats, checking the fixable box and pushing this
button will tell calibre that the formats are really gone. Use this if
you are not going to restore the formats from a backup.</p>
'''))
self.log = QTreeWidget(self)
self.log.itemChanged.connect(self.item_changed)
self.log.itemExpanded.connect(self.item_expanded_or_collapsed)
self.log.itemCollapsed.connect(self.item_expanded_or_collapsed)
self._layout.addWidget(self.log)
self.check_button = QPushButton(_('&Run the check again'))
self.check_button.setDefault(False)
self.check_button.clicked.connect(self.run_the_check)
self.copy_button = QPushButton(_('Copy &to clipboard'))
self.copy_button.setDefault(False)
self.copy_button.clicked.connect(self.copy_to_clipboard)
self.ok_button = QPushButton(_('&Done'))
self.ok_button.setDefault(True)
self.ok_button.clicked.connect(self.accept)
self.mark_delete_button = QPushButton(_('Mark &all for delete'))
self.mark_delete_button.setToolTip(_('Mark all deletable subitems'))
self.mark_delete_button.setDefault(False)
#.........这里部分代码省略.........
示例15: selectedIndexes
def selectedIndexes(self):
ans = QTreeWidget.selectedIndexes(self)
if self.ordered_selected_indexes:
ans = list(sorted(ans, key=lambda idx:idx.row()))
return ans