本文整理汇总了Python中PyQt4.Qt.QTreeView类的典型用法代码示例。如果您正苦于以下问题:Python QTreeView类的具体用法?Python QTreeView怎么用?Python QTreeView使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTreeView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, *args):
QTreeView.__init__(self, *args)
self.setStyleSheet('''
QTreeView {
background-color: palette(window);
color: palette(window-text);
border: none;
}
QTreeView::item {
border: 1px solid transparent;
padding-top:0.5ex;
padding-bottom:0.5ex;
}
QTreeView::item:hover {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1);
border: 1px solid #bfcde4;
border-radius: 6px;
}
QHeaderView::section {
background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
stop:0 #616161, stop: 0.5 #505050,
stop: 0.6 #434343, stop:1 #656565);
color: white;
padding-left: 4px;
padding-top: 0.5ex;
padding-bottom: 0.5ex;
border: 1px solid #6c6c6c;
font-weight: bold;
}
''')
示例2: __init__
def __init__(self, name, ne1model, parent=None):
QTreeView.__init__(self, parent)
self.ne1model = ne1model
ne1model.view = self
self.setSelectionMode(self.ExtendedSelection) #bruce 070507 MultiSelection -> ExtendedSelection
self.qtmodel = None
self.drag = None
self.setAcceptDrops(True)
示例3: __init__
def __init__(self, name, treemodel, parent=None):
QTreeView.__init__(self, parent)
self.treemodel = treemodel #bruce 081216 renamed this from ne1model
treemodel.view = self
self.setSelectionMode(self.ExtendedSelection) #bruce 070507 MultiSelection -> ExtendedSelection
self.qtmodel = None
self.drag = None
self.setAcceptDrops(True)
示例4: __init__
def __init__(self, parent=None):
QTreeView.__init__(self, parent=None)
self.alter_tb = None
self.disable_recounting = False
self.setUniformRowHeights(True)
self.setCursor(Qt.PointingHandCursor)
self.setIconSize(QSize(20, 20))
self.setTabKeyNavigation(True)
self.setAnimated(True)
self.setHeaderHidden(True)
self.setItemDelegate(TagDelegate(self))
self.made_connections = False
self.setAcceptDrops(True)
self.setDragEnabled(True)
self.setDragDropMode(self.DragDrop)
self.setDropIndicatorShown(True)
self.in_drag_drop = False
self.setAutoExpandDelay(500)
self.pane_is_visible = False
self.search_icon = QIcon(I("search.png"))
self.user_category_icon = QIcon(I("tb_folder.png"))
self.delete_icon = QIcon(I("list_remove.png"))
self.rename_icon = QIcon(I("edit-undo.png"))
self._model = TagsModel(self)
self._model.search_item_renamed.connect(self.search_item_renamed)
self._model.refresh_required.connect(self.refresh_required, type=Qt.QueuedConnection)
self._model.tag_item_renamed.connect(self.tag_item_renamed)
self._model.restriction_error.connect(self.restriction_error)
self._model.user_categories_edited.connect(self.user_categories_edited, type=Qt.QueuedConnection)
self._model.drag_drop_finished.connect(self.drag_drop_finished)
stylish_tb = """
QTreeView {
background-color: palette(window);
color: palette(window-text);
border: none;
}
"""
self.setStyleSheet(
"""
QTreeView::item {
border: 1px solid transparent;
padding-top:0.9ex;
padding-bottom:0.9ex;
}
QTreeView::item:hover {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1);
border: 1px solid #bfcde4;
border-radius: 6px;
}
"""
+ ("" if gprefs["tag_browser_old_look"] else stylish_tb)
)
if gprefs["tag_browser_old_look"]:
self.setAlternatingRowColors(True)
示例5: __init__
def __init__(self, *args):
QTreeView.__init__(self,*args)
self._model = Matches()
self.setModel(self._model)
self.rt_delegate = RichTextDelegate(self)
for i in self._model.HTML_COLS:
self.setItemDelegateForColumn(i, self.rt_delegate)
示例6: __init__
def __init__(self, parent=None):
QTreeView.__init__(self, parent)
self.setHeaderHidden(True)
self.setAnimated(True)
self.activated.connect(self.item_activated)
self.clicked.connect(self.item_activated)
pi = plugins['progress_indicator'][0]
if hasattr(pi, 'set_no_activate_on_click'):
pi.set_no_activate_on_click(self)
self.initialized = False
self.setExpandsOnDoubleClick(False)
示例7: __init__
def __init__(self, process, block):
QTreeView.__init__(self)
model = BlockModel(process, block)
self.setModel(model)
self.setWindowTitle("%s: imalcolm" % model.block_path[0])
root = os.path.join(os.path.dirname(__file__), "..", "..")
icon_path = os.path.join(root, "docs", "malcolm-logo.svg")
self.setWindowIcon(QIcon(icon_path))
self.setColumnWidth(0, 160)
self.setColumnWidth(1, 180)
self.setColumnWidth(2, 25)
self.resize(QSize(370, 500))
self.setItemDelegateForColumn(1, Delegate())
self.setEditTriggers(self.AllEditTriggers)
self.expanded.connect(self.write_expanded)
self.collapsed.connect(self.write_collapsed)
示例8: __init__
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self._layout = l = QGridLayout()
self.setLayout(self._layout)
self.header = QLabel(_('Double click on any entry to change the'
' keyboard shortcuts associated with it'))
l.addWidget(self.header, 0, 0, 1, 3)
self.view = QTreeView(self)
self.view.setAlternatingRowColors(True)
self.view.setHeaderHidden(True)
self.view.setAnimated(True)
l.addWidget(self.view, 1, 0, 1, 3)
self.delegate = Delegate()
self.view.setItemDelegate(self.delegate)
self.delegate.sizeHintChanged.connect(self.editor_opened,
type=Qt.QueuedConnection)
self.delegate.changed_signal.connect(self.changed_signal)
self.search = SearchBox2(self)
self.search.initialize('shortcuts_search_history',
help_text=_('Search for a shortcut by name'))
self.search.search.connect(self.find)
l.addWidget(self.search, 2, 0, 1, 1)
self.nb = QPushButton(QIcon(I('arrow-down.png')), _('&Next'), self)
self.pb = QPushButton(QIcon(I('arrow-up.png')), _('&Previous'), self)
self.nb.clicked.connect(self.find_next)
self.pb.clicked.connect(self.find_previous)
l.addWidget(self.nb, 2, 1, 1, 1)
l.addWidget(self.pb, 2, 2, 1, 1)
l.setColumnStretch(0, 100)
示例9: resizeEvent
def resizeEvent(self, evt):
"""
Reimplementation of resizeEvent method of QTreeView
"""
if self.selectedItem() is not None:
self.parent.partChanged(self.selectedItem())
return QTreeView.resizeEvent(self, evt)
示例10: __init__
def __init__(self, *args):
QTreeView.__init__(self,*args)
self._model = Matches([p for p in store_plugins()])
self.setModel(self._model)
self.setIconSize(QSize(24, 24))
self.rt_delegate = RichTextDelegate(self)
for i in self._model.HTML_COLS:
self.setItemDelegateForColumn(i, self.rt_delegate)
for i in xrange(self._model.columnCount()):
self.resizeColumnToContents(i)
self.model().sort(1, Qt.AscendingOrder)
self.header().setSortIndicator(self.model().sort_col, self.model().sort_order)
示例11: __init__
def __init__(self, mmkit, parent):
QTreeView.__init__(self, parent)
self.setEnabled(True)
self.model = QtGui.QDirModel(['*.mmp', '*.MMP'], # name filters
QDir.AllEntries|QDir.AllDirs|QDir.NoDotAndDotDot, # filters
QDir.Name # sort order
)
# explanation of filters (from Qt 4.2 doc for QDirModel):
# - QDir.AllEntries = list files, dirs, drives, symlinks.
# - QDir.AllDirs = include dirs regardless of other filters [guess: needed to ignore the name filters for dirs]
# - QDir.NoDotAndDotDot = don't include '.' and '..' dirs
#
# about dirnames of "CVS":
# The docs don't mention any way to filter the dirnames using a callback,
# or any choices besides "filter them same as filenames" or "don't filter them".
# So there is no documented way to filter out the "CVS" subdirectories like we did in Qt3
# (short of subclassing this and overriding some methods,
# but the docs don't make it obvious how to do that correctly).
# Fortunately, autoBuild.py removes them from the partlib copy in built releases.
#
# Other QDirModel methods we might want to use:
# QDirModel.refresh, to update its state from the filesystem (but see the docs --
# they imply we might have to pass the model's root pathname to that method,
# even if it hasn't changed, but they're not entirely clear on that).
#
# [bruce 070502 comments]
self.path = None
self.mmkit = mmkit
self.setModel(self.model)
self.setWindowTitle(self.tr("Dir View"))
self.setItemsExpandable(True)
self.setAlternatingRowColors(True)
self.setColumnWidth(0, 200)
for i in range(2,4):
self.setColumnWidth(i, 4)
self.show()
示例12: mouseMoveEvent
def mouseMoveEvent(self, event):
dex = self.indexAt(event.pos())
if self.in_drag_drop or not dex.isValid():
QTreeView.mouseMoveEvent(self, event)
return
# Must deal with odd case where the node being dragged is 'virtual',
# created to form a hierarchy. We can't really drag this node, but in
# addition we can't allow drag recognition to notice going over some
# other node and grabbing that one. So we set in_drag_drop to prevent
# this from happening, turning it off when the user lifts the button.
self.in_drag_drop = True
if not self._model.flags(dex) & Qt.ItemIsDragEnabled:
QTreeView.mouseMoveEvent(self, event)
return
md = self._model.mimeData([dex])
pixmap = dex.data(Qt.DecorationRole).toPyObject().pixmap(25, 25)
drag = QDrag(self)
drag.setPixmap(pixmap)
drag.setMimeData(md)
if self._model.is_in_user_category(dex):
drag.exec_(Qt.CopyAction|Qt.MoveAction, Qt.CopyAction)
else:
drag.exec_(Qt.CopyAction)
示例13: dragMoveEvent
def dragMoveEvent(self, event):
QTreeView.dragMoveEvent(self, event)
self.setDropIndicatorShown(False)
index = self.indexAt(event.pos())
if not index.isValid():
return
src_is_tb = event.mimeData().hasFormat('application/calibre+from_tag_browser')
item = index.data(Qt.UserRole).toPyObject()
if item.type == TagTreeItem.ROOT:
return
flags = self._model.flags(index)
if item.type == TagTreeItem.TAG and flags & Qt.ItemIsDropEnabled:
self.setDropIndicatorShown(not src_is_tb)
return
if item.type == TagTreeItem.CATEGORY and not item.is_gst:
fm_dest = self.db.metadata_for_field(item.category_key)
if fm_dest['kind'] == 'user':
if src_is_tb:
if event.dropAction() == Qt.MoveAction:
data = str(event.mimeData().data('application/calibre+from_tag_browser'))
src = cPickle.loads(data)
for s in src:
if s[0] == TagTreeItem.TAG and \
(not s[1].startswith('@') or s[2]):
return
self.setDropIndicatorShown(True)
return
md = event.mimeData()
if hasattr(md, 'column_name'):
fm_src = self.db.metadata_for_field(md.column_name)
if md.column_name in ['authors', 'publisher', 'series'] or \
(fm_src['is_custom'] and (
(fm_src['datatype'] in ['series', 'text', 'enumeration'] and
not fm_src['is_multiple']) or
(fm_src['datatype'] == 'composite' and
fm_src['display'].get('make_category', False)))):
self.setDropIndicatorShown(True)
示例14: dragMoveEvent
def dragMoveEvent(self, event):
QTreeView.dragMoveEvent(self, event)
self.setDropIndicatorShown(False)
index = self.indexAt(event.pos())
if not index.isValid():
return
src_is_tb = event.mimeData().hasFormat("application/calibre+from_tag_browser")
item = index.data(Qt.UserRole).toPyObject()
if item.type == TagTreeItem.ROOT:
return
flags = self._model.flags(index)
if item.type == TagTreeItem.TAG and flags & Qt.ItemIsDropEnabled:
self.setDropIndicatorShown(not src_is_tb)
return
if item.type == TagTreeItem.CATEGORY and not item.is_gst:
fm_dest = self.db.metadata_for_field(item.category_key)
if fm_dest["kind"] == "user":
if src_is_tb:
if event.dropAction() == Qt.MoveAction:
data = str(event.mimeData().data("application/calibre+from_tag_browser"))
src = cPickle.loads(data)
for s in src:
if s[0] == TagTreeItem.TAG and (not s[1].startswith("@") or s[2]):
return
self.setDropIndicatorShown(True)
return
md = event.mimeData()
if hasattr(md, "column_name"):
fm_src = self.db.metadata_for_field(md.column_name)
if md.column_name in ["authors", "publisher", "series"] or (
fm_src["is_custom"]
and (
(fm_src["datatype"] in ["series", "text", "enumeration"] and not fm_src["is_multiple"])
or (fm_src["datatype"] == "composite" and fm_src["display"].get("make_category", False))
)
):
self.setDropIndicatorShown(True)
示例15: ShortcutConfig
class ShortcutConfig(QWidget): # {{{
changed_signal = pyqtSignal()
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self._layout = l = QGridLayout()
self.setLayout(self._layout)
self.header = QLabel(_('Double click on any entry to change the'
' keyboard shortcuts associated with it'))
l.addWidget(self.header, 0, 0, 1, 3)
self.view = QTreeView(self)
self.view.setAlternatingRowColors(True)
self.view.setHeaderHidden(True)
self.view.setAnimated(True)
l.addWidget(self.view, 1, 0, 1, 3)
self.delegate = Delegate()
self.view.setItemDelegate(self.delegate)
self.delegate.sizeHintChanged.connect(self.editor_opened,
type=Qt.QueuedConnection)
self.delegate.changed_signal.connect(self.changed_signal)
self.search = SearchBox2(self)
self.search.initialize('shortcuts_search_history',
help_text=_('Search for a shortcut by name'))
self.search.search.connect(self.find)
l.addWidget(self.search, 2, 0, 1, 1)
self.nb = QPushButton(QIcon(I('arrow-down.png')), _('&Next'), self)
self.pb = QPushButton(QIcon(I('arrow-up.png')), _('&Previous'), self)
self.nb.clicked.connect(self.find_next)
self.pb.clicked.connect(self.find_previous)
l.addWidget(self.nb, 2, 1, 1, 1)
l.addWidget(self.pb, 2, 2, 1, 1)
l.setColumnStretch(0, 100)
def restore_defaults(self):
self._model.restore_defaults()
self.changed_signal.emit()
def commit(self):
if self.view.state() == self.view.EditingState:
self.delegate.accept_changes()
self._model.commit()
def initialize(self, keyboard):
self._model = ConfigModel(keyboard, parent=self)
self.view.setModel(self._model)
def editor_opened(self, index):
self.view.scrollTo(index, self.view.EnsureVisible)
@property
def is_editing(self):
return self.view.state() == self.view.EditingState
def find(self, query):
if not query:
return
try:
idx = self._model.find(query)
except ParseException:
self.search.search_done(False)
return
self.search.search_done(True)
if not idx.isValid():
info_dialog(self, _('No matches'),
_('Could not find any shortcuts matching %s')%query,
show=True, show_copy_button=False)
return
self.highlight_index(idx)
def highlight_index(self, idx):
self.view.scrollTo(idx)
self.view.selectionModel().select(idx,
self.view.selectionModel().ClearAndSelect)
self.view.setCurrentIndex(idx)
self.view.setFocus(Qt.OtherFocusReason)
def find_next(self, *args):
idx = self.view.currentIndex()
if not idx.isValid():
idx = self._model.index(0, 0)
idx = self._model.find_next(idx,
unicode(self.search.currentText()))
self.highlight_index(idx)
def find_previous(self, *args):
idx = self.view.currentIndex()
if not idx.isValid():
idx = self._model.index(0, 0)
idx = self._model.find_next(idx,
unicode(self.search.currentText()), backwards=True)
self.highlight_index(idx)
def highlight_group(self, group_name):
idx = self.view.model().index_for_group(group_name)
if idx is not None:
self.view.expand(idx)
self.view.scrollTo(idx, self.view.PositionAtTop)
self.view.selectionModel().select(idx,
self.view.selectionModel().ClearAndSelect)
#.........这里部分代码省略.........