本文整理汇总了Python中PyQt5.QtWidgets.QTreeView类的典型用法代码示例。如果您正苦于以下问题:Python QTreeView类的具体用法?Python QTreeView怎么用?Python QTreeView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTreeView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GetNodeDialog
class GetNodeDialog(QDialog):
def __init__(self, parent, startnode, currentnode=None):
QDialog.__init__(self, parent)
layout = QVBoxLayout(self)
self.treeview = QTreeView(self)
self.treeview.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.tree = TreeWidget(self.treeview)
self.tree.set_root_node(startnode)
layout.addWidget(self.treeview)
self.buttons = QDialogButtonBox(
QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
Qt.Horizontal, self)
layout.addWidget(self.buttons)
self.resize(800, 600)
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)
self.treeview.activated.connect(self.accept)
if currentnode:
self.tree.expand_to_node(currentnode)
def get_node(self):
return self.tree.get_current_node()
@staticmethod
def getNode(parent, startnode, currentnode=None):
dialog = GetNodeDialog(parent, startnode, currentnode)
result = dialog.exec_()
node = dialog.get_node()
return node, result == QDialog.Accepted
示例2: MainWindow
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.fileMenu = self.menuBar().addMenu("&File")
self.fileMenu.addAction("&Open...", self.openFile, "Ctrl+O")
self.fileMenu.addAction("E&xit", self.close, "Ctrl+Q")
self.xmlPath = ""
self.model = DomModel(QDomDocument(), self)
self.view = QTreeView(self)
self.view.setModel(self.model)
self.setCentralWidget(self.view)
self.setWindowTitle("Simple DOM Model")
def openFile(self):
filePath, _ = QFileDialog.getOpenFileName(self, "Open File",
self.xmlPath, "XML files (*.xml);;HTML files (*.html);;"
"SVG files (*.svg);;User Interface files (*.ui)")
if filePath:
f = QFile(filePath)
if f.open(QIODevice.ReadOnly):
document = QDomDocument()
if document.setContent(f):
newModel = DomModel(document, self)
self.view.setModel(newModel)
self.model = newModel
self.xmlPath = filePath
f.close()
示例3: mousePressEvent
def mousePressEvent(self, event):
if event.button() == Qt.RightButton:
# Capture mouse press so that selection doesn't change
# on right click
pass
else:
QTreeView.mousePressEvent(self, event)
示例4: setModel
def setModel(self, model):
QTreeView.setModel(self, model)
# Setting delegates
self.outlineTitleDelegate = outlineTitleDelegate(self)
# self.outlineTitleDelegate.setView(self)
self.setItemDelegateForColumn(Outline.title, self.outlineTitleDelegate)
self.outlineCharacterDelegate = outlineCharacterDelegate(self.modelCharacters)
self.setItemDelegateForColumn(Outline.POV, self.outlineCharacterDelegate)
self.outlineCompileDelegate = outlineCompileDelegate()
self.setItemDelegateForColumn(Outline.compile, self.outlineCompileDelegate)
self.outlineStatusDelegate = outlineStatusDelegate(self.modelStatus)
self.setItemDelegateForColumn(Outline.status, self.outlineStatusDelegate)
self.outlineGoalPercentageDelegate = outlineGoalPercentageDelegate()
self.setItemDelegateForColumn(Outline.goalPercentage, self.outlineGoalPercentageDelegate)
self.outlineLabelDelegate = outlineLabelDelegate(self.modelLabels)
self.setItemDelegateForColumn(Outline.label, self.outlineLabelDelegate)
# Hiding columns
self.hideColumns()
self.header().setSectionResizeMode(Outline.title, QHeaderView.Stretch)
self.header().setSectionResizeMode(Outline.POV, QHeaderView.ResizeToContents)
self.header().setSectionResizeMode(Outline.status, QHeaderView.ResizeToContents)
self.header().setSectionResizeMode(Outline.label, QHeaderView.ResizeToContents)
self.header().setSectionResizeMode(Outline.compile, QHeaderView.ResizeToContents)
self.header().setSectionResizeMode(Outline.wordCount, QHeaderView.ResizeToContents)
self.header().setSectionResizeMode(Outline.goal, QHeaderView.ResizeToContents)
self.header().setSectionResizeMode(Outline.goalPercentage, QHeaderView.ResizeToContents)
示例5: blockSignals
def blockSignals(self, block):
"""
Blocks the signals from this class. Subclassed in order to also block
selectionChanged "signal" (callback) options
@param block: whether to block signal (True) or not (False)
"""
self.signals_blocked = block
QTreeView.blockSignals(self, block)
示例6: __init__
def __init__(self, parent=None, cols=None, **kwargs):
QTreeView.__init__(self, parent=parent, **kwargs)
self.setSortingEnabled(True)
self.setAlternatingRowColors(True)
if cols != None:
model = VQTreeModel(parent=self, columns=cols)
self.setModel( model )
示例7: setModel
def setModel(self, model):
QTreeView.setModel(self, model)
# Hiding columns
for c in range(1, self.model().columnCount()):
self.hideColumn(c)
# Setting delegate
self.titleDelegate = treeTitleDelegate()
self.setItemDelegateForColumn(Outline.title.value, self.titleDelegate)
示例8: __init__
def __init__(self, parent=None, modelCharacters=None, modelLabels=None, modelStatus=None):
QTreeView.__init__(self, parent)
dndView.__init__(self)
outlineBasics.__init__(self, parent)
self.modelCharacters = modelCharacters
self.modelLabels = modelLabels
self.modelStatus = modelStatus
self.header().setStretchLastSection(False)
示例9: selectionChanged
def selectionChanged(self, selected, deselected):
"""
Function called by QT when the selection has changed for this treeView.
Subclassed in order to call a callback function options
@param selected: list of selected items
@param deselected: list of deselected items
print("\033[32;1mselectionChanged selected count = {0} ; deselected count = {1}\033[m".format(selected.count(), deselected.count()))
"""
QTreeView.selectionChanged(self, selected, deselected)
if self.selectionChangedcallback and not self.signals_blocked:
self.selectionChangedcallback(self, selected, deselected)
示例10: __init__
def __init__(self, fileBrowser):
QTreeView.__init__(self, fileBrowser)
self._fileBrowser = fileBrowser
self.setAttribute(Qt.WA_MacShowFocusRect, False)
self.setAttribute(Qt.WA_MacSmallSize)
self.setContextMenuPolicy(Qt.ActionsContextMenu)
self.setHeaderHidden(True)
self.setUniformRowHeights(True)
self.setTextElideMode(Qt.ElideMiddle)
# dir model
self._dirsModel = _FileSystemModel(self)
self._dirsModel.setNameFilterDisables(False)
self._dirsModel.setFilter(QDir.AllDirs | QDir.AllEntries | QDir.CaseSensitive | QDir.NoDotAndDotDot)
# self._dirsModel.directoryLoaded.connect(self.setFocus) TODO don't have this signal in my Qt version
# create proxy model
self._filteredModel = FileBrowserFilteredModel(self)
self._filteredModel.setSourceModel(self._dirsModel)
self.setModel(self._filteredModel)
if not sys.platform.startswith('win'):
self._dirsModel.setRootPath("/")
else:
self._dirsModel.setRootPath('')
# shortcut accessible only when self._tree has focus
self._upShortcut = QShortcut(QKeySequence("BackSpace"), self)
self._upShortcut.setContext(Qt.WidgetShortcut)
self._upShortcut.activated.connect(self.moveUp)
# shortcut accessible only when self._tree has focus
self._homeShortcut = QShortcut(QKeySequence("`"), self)
self._homeShortcut.setContext(Qt.WidgetShortcut)
self._homeShortcut.activated.connect(self._goUserHomeDir)
# shortcut accessible only when self._tree has focus
self._homeShortcut = QShortcut(QKeySequence("."), self)
self._homeShortcut.setContext(Qt.WidgetShortcut)
self._homeShortcut.activated.connect(self._goCurrentDir)
self.activated.connect(self._onActivated)
self._fileActivated.connect(fileBrowser.fileActivated)
# QDirModel loads item asynchronously, therefore we need timer for setting focus to the first item
self._setFocusTimer = QTimer()
self._setFocusTimer.timeout.connect(self._setFirstItemAsCurrent)
self._setFocusTimer.setInterval(50)
self._timerAttempts = 0
示例11: __init__
def __init__(self, parent = None):
"""
Initialization of the TreeView class.
"""
QTreeView.__init__(self, parent)
self.dragged_element = False #No item is currently dragged & dropped
self.dragged_element_model_index = None
self.selectionChangedcallback = None
self.keyPressEventcallback = None
self.signals_blocked = False #Transmit events between classes
self.pressed.connect(self.elementPressed)
示例12: _mock_view_index
def _mock_view_index(model, category_idx, child_idx, qtbot):
"""Create a tree view from a model and set the current index.
Args:
model: model to create a fake view for.
category_idx: index of the category to select.
child_idx: index of the child item under that category to select.
"""
view = QTreeView()
qtbot.add_widget(view)
view.setModel(model)
idx = model.indexFromItem(model.item(category_idx).child(child_idx))
view.setCurrentIndex(idx)
return view
示例13: keyPressEvent
def keyPressEvent(self, keyEvent):
"""
Function called by QT when a key has been pressed inside the treeView.
Subclassed in order to call a callback function
@param keyEvent: keyboard event
print("\033[31;1mkeyPressEvent() key = {0}\033[m".format(keyEvent.key()))
"""
if self.keyPressEventcallback and not self.signals_blocked:
if not self.keyPressEventcallback(keyEvent):
# key not accepted => send it back to the parent
QTreeView.keyPressEvent(self, keyEvent)
else:
QTreeView.keyPressEvent(self, keyEvent)
示例14: __init__
def __init__(self, projects, parent=None):
super(AddToProject, self).__init__(parent)
#pathProjects must be a list
self._projects = projects
self.setWindowTitle(translations.TR_ADD_FILE_TO_PROJECT)
self.pathSelected = ''
vbox = QVBoxLayout(self)
hbox = QHBoxLayout()
self._list = QListWidget()
for project in self._projects:
self._list.addItem(project.name)
self._list.setCurrentRow(0)
self._tree = QTreeView()
#self._tree.header().setHidden(True)
self._tree.setSelectionMode(QTreeView.SingleSelection)
self._tree.setAnimated(True)
self.load_tree(self._projects[0])
hbox.addWidget(self._list)
hbox.addWidget(self._tree)
vbox.addLayout(hbox)
hbox2 = QHBoxLayout()
btnAdd = QPushButton(translations.TR_ADD_HERE)
btnCancel = QPushButton(translations.TR_CANCEL)
hbox2.addWidget(btnCancel)
hbox2.addWidget(btnAdd)
vbox.addLayout(hbox2)
btnCancel.connect(self.close)
btnAdd.connect(self._select_path)
self._list.currentItemChanged['QTreeWidgetItem*', 'QTreeWidgetItem*'].connect(self._project_changed)
示例15: _createUi
def _createUi(self):
self.setWindowTitle(core.project().path().replace(os.sep, '/') or 'Locator')
self.setLayout(QVBoxLayout())
self.layout().setContentsMargins(0, 0, 0, 0)
self.layout().setSpacing(1)
biggerFont = self.font()
biggerFont.setPointSizeF(biggerFont.pointSizeF() * 2)
self.setFont(biggerFont)
self._edit = _CompletableLineEdit(self)
self._edit.updateCurrentCommand.connect(self._updateCurrentCommand)
self._edit.enterPressed.connect(self._onEnterPressed)
self._edit.installEventFilter(self) # catch Up, Down
self._edit.setFont(biggerFont)
self.layout().addWidget(self._edit)
self.setFocusProxy(self._edit)
self._table = QTreeView(self)
self._table.setFont(biggerFont)
self._model = _CompleterModel()
self._table.setModel(self._model)
self._table.setItemDelegate(HTMLDelegate(self._table))
self._table.setRootIsDecorated(False)
self._table.setHeaderHidden(True)
self._table.clicked.connect(self._onItemClicked)
self._table.setAlternatingRowColors(True)
self._table.installEventFilter(self) # catch focus and give to the edit
self.layout().addWidget(self._table)
width = QFontMetrics(self.font()).width('x' * 64) # width of 64 'x' letters
self.resize(width, width * 0.62)