本文整理汇总了Python中PyQt4.Qt.QTreeWidget类的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidget类的具体用法?Python QTreeWidget怎么用?Python QTreeWidget使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTreeWidget类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, parent=None):
QTreeWidget.__init__(self, parent)
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.itemDoubleClicked.connect(self.item_double_clicked)
示例2: __init__
def __init__(self, storage, show_files):
QTreeWidget.__init__(self)
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)
示例3: mouseReleaseEvent
def mouseReleaseEvent(self, ev):
item = self.itemAt(self._mouse_press_pos)
if item:
col = self.header().logicalIndexAt(self._mouse_press_pos)
# pass event to parent
QTreeWidget.mouseReleaseEvent(self, ev)
# now see if the item was expanded or collapsed because of the event. Only emit signal if this was
# not the case (i.e. swallow the clicks that have to do with expansion/collapse of items)
if item and item is not self._expanded_item:
self.emit(SIGNAL("mouseButtonClicked"), ev.button(), item, self._mouse_press_pos, col)
示例4: __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
示例5: __init__
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.l = l = QGridLayout(self)
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
示例6: __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)
示例7: __init__
def __init__(self, parent=None):
QTreeWidget.__init__(self, parent)
self.delegate = ItemDelegate(self)
self.setTextElideMode(Qt.ElideMiddle)
self.setItemDelegate(self.delegate)
self.header().close()
self.setDragEnabled(True)
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.in_drop_event = False
self.setContextMenuPolicy(Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.show_context_menu)
self.root = self.invisibleRootItem()
示例8: __init__
def __init__(self, parent=None, name=None):
QTreeWidget.__init__(self, parent)
global folderClosedIcon, folderLockedIcon, folderOpenIcon, fileIcon
folderClosedIcon = QIcon(QPixmap(folder_closed_image))
folderLockedIcon = QIcon(QPixmap(folder_locked_image))
folderOpenIcon = QIcon(QPixmap(folder_open_image))
fileIcon = QIcon(QPixmap(pix_file_image))
self.setHeaderLabels(["", "Name"])
#self.addColumn("Name", 150) # added 150. mark 060303. [bruce then changed 'width=150' to '150' to avoid exception]
# Calling addColumn() here causes DirView to change size after its parent (MMKit) is shown.
# I've not been successful figuring out how to control the height of the DirView (QTreeWidget)
# after adding this column. See comments in MWsemantics._findGoodLocation() for more
# information about how I compensate for this. Mark 060222.
#self.setGeometry(QRect(7,-1,191,150))
self.setMinimumSize(QSize(160,150))
# Trying to force height to be 150, but addColumn() overrides this. To see the problem,
# simply comment out addColumn() above and enter Build mode. mark 060222.
#self.setSizePolicy(QSizePolicy(QSizePolicy.MinimumExpanding,QSizePolicy.MinimumExpanding,0,0,self.sizePolicy().hasHeightForWidth()))
qt4todo('self.setTreeStepSize(20)')
qt4todo('self.setColumnWidth(0, 150)') # Force the column width to 150 again. Fixes bug 1613. mark 060303.
示例9: __init__
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.l = l = QGridLayout(self)
self.setLayout(l)
l.setContentsMargins(0, 0, 0, 0)
self.is_visible = False
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.build)
示例10: 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.delete_button = QPushButton(_('Delete &marked'))
self.delete_button.setToolTip(_('Delete marked files (checked subitems)'))
self.delete_button.setDefault(False)
#.........这里部分代码省略.........
示例11: 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)
示例12: mousePressEvent
def mousePressEvent(self, ev):
self._expanded_item = None
self._mouse_press_pos = ev.pos()
QTreeWidget.mousePressEvent(self, ev)
示例13: viewportEvent
def viewportEvent(self, event):
if event.type() in (QEvent.Leave, QEvent.FocusOut) and self.model:
self.model.setCurrentSource(None, origin=self)
return QTreeWidget.viewportEvent(self, event)
示例14: TOCViewer
class TOCViewer(QWidget):
navigate_requested = pyqtSignal(object, object)
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.l = l = QGridLayout(self)
self.setLayout(l)
l.setContentsMargins(0, 0, 0, 0)
self.is_visible = False
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.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 iteritems(self, parent=None):
if parent is None:
parent = self.invisibleRootItem()
for i in xrange(parent.childCount()):
child = parent.child(i)
yield child
for gc in self.iteritems(parent=child):
yield gc
def emit_navigate(self, *args):
item = self.view.currentItem()
if item is not None:
dest = unicode(item.data(0, DEST_ROLE).toString())
frag = unicode(item.data(0, FRAG_ROLE).toString())
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)
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)
self.view.clear()
process_node(toc, self.view.invisibleRootItem())
def visibility_changed(self, visible):
self.is_visible = visible
if visible:
self.build()
def update_if_visible(self):
if self.is_visible:
self.build()
示例15: __init__
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.delete_button = QPushButton(_('Delete &marked'))
self.delete_button.setToolTip(_('Delete marked files (checked subitems)'))
self.delete_button.setDefault(False)
self.delete_button.clicked.connect(self.delete_marked)
self.fix_button = QPushButton(_('&Fix marked'))
#.........这里部分代码省略.........