qabstractitemmodel

QTreeView and QAbstractItemModel

霸气de小男生 提交于 2019-12-13 02:13:09
问题 I'm new to Qt and I'm trying to make a simple tree based on a flat (or from a sqlite table) file paths list (not from FS) like this: C:\Parent1\Child1\Leaf1.jpg C:\Parent1\Child1\Leaf2.jpg C:\Parent1\Child1\Leaf3.jpg C:\Parent1\Child2\Leaf1.jpg C:\Parent1\Child2\Leaf2.jpg C:\Parent2\Child1\Leaf1.jpg C:\Parent2\Child1\Leaf2.jpg ... D:\.... ... I'd like to display this as a tree view (e.g. a file explorer). I looked into QAbstractItemModel but I have some difficulties to build the tree. My idea

looking for example for QCompleter with segmented completion / tree models

依然范特西╮ 提交于 2019-12-12 20:19:31
问题 The PySide docs include this section on QCompleter with tree models: PySide.QtGui.QCompleter can look for completions in tree models, assuming that any item (or sub-item or sub-sub-item) can be unambiguously represented as a string by specifying the path to the item. The completion is then performed one level at a time. Let’s take the example of a user typing in a file system path. The model is a (hierarchical) PySide.QtGui.QFileSystemModel . The completion occurs for every element in the

QStandardItemModel: any efficient way to add a batch of items?

故事扮演 提交于 2019-12-12 02:43:48
问题 Is there any efficient way to add a batch of QStandardItem s to a model? The model is being cleared and then I'm adding a lot of items. QtreeWidget has addTopLevelItems ( const QList<QTreeWidgetItem *> & items ) for just this, how to optimize such addition with model / view architecture? 来源: https://stackoverflow.com/questions/19694316/qstandarditemmodel-any-efficient-way-to-add-a-batch-of-items

Specializing a QAbstractProxyModel for adding a column: the table cells becomes empty

老子叫甜甜 提交于 2019-12-12 02:43:27
问题 I have created a mixin-like proxy model (Qt5) which just adds an extra first column to another proxy model, for adding a QToolBar of actions to each row of the table view (for example, a "delete" button). The model just provides a way of populating a QList<QVariant> for the first column. The delegate must know what is the meaning of each QVariant (usually int s/ enum s identifying actions), and populate the QToolBar accordingly. As last feature, if there's no actions, no extra column is added

QAbstractItemModel: annoying branch line in QTreeView

此生再无相见时 提交于 2019-12-12 02:12:53
问题 I've made a minimalistic subclass of QAbstractItemModel . It works, but in QTreeView there is a odd branch line that should not appear here (because there is no more items after [Sensor arrays] section). Cannot you tell me, what have I done wrong and how to fix it? Here is my code: import os, sys from PyQt5 import QtCore, QtGui, QtWidgets import treelib class BlockHierarchyNode(object): def __init__(self, icon_path=None, name="", description="", is_category=False): if icon_path is not None:

Not able to see plus sign even if I pass true from hasChildren function in Qt

情到浓时终转凉″ 提交于 2019-12-11 18:24:10
问题 I am implementing tree view, I have sub classed my model and view. initially I am populating all the top level items and I don't know how many child's are there for each top level items but I know all the top level items has a child's, so I have re-implemented hasChildren() function and pass true for all the top level items, but I am not able to see + sign for the top level items even i pass true. Please let me know the problem Thanks in advance. 来源: https://stackoverflow.com/questions

QTreeView: maintaining mapping between QModelIndex and underlying data

帅比萌擦擦* 提交于 2019-12-11 08:56:12
问题 I have problems migrating from QTreeWidget to QtreeView . Things that were obvious and trivial with QTreeWidget seem to be impossible with view. Specifically: I have a main window with a treeview in it. TreeView uses the model I've implemented, but not directly – through QSortFilterProxyModel that is set as a tree's model. Now, the user activates an item in the tree and main windows receives a signal itemActivated(QModelIndex item) . How can I tell which item of the underlying data was

QModelIndex becomes invalid when removing rows

吃可爱长大的小学妹 提交于 2019-12-10 16:06:48
问题 I'm subclassing QAbstractItemModel to display items in a QTreeView , and within this subclass ( projectModel ), I have a function to delete the currently-selected index in the tree view. Component is the class used to represent all the members of the model: void projectModel::deleteComponent() { QModelIndex child_index = _treeview->selectionModel()->currentIndex(); Component* child = static_cast<Component*>(child_index.internalPointer()); Component* parent = child->Parent(); QModelIndex

How do I get my python object back from a QVariant in PyQt4?

孤人 提交于 2019-12-10 14:10:28
问题 I am creating a subclass of QAbstractItemModel to be displayed in an QTreeView . My index() and parent() function creates the QModelIndex using the QAbstractItemModel inherited function createIndex and providing it the row , column , and data needed. Here, for testing purposes, data is a Python string. class TestModel(QAbstractItemModel): def __init__(self): QAbstractItemModel.__init__(self) def index(self, row, column, parent): if parent.isValid(): return self.createIndex(row, column, "bar")

pyqt: Trying to understand insertrows for QAbstractDataModel and QTreeView

三世轮回 提交于 2019-12-10 03:48:54
问题 I am using PyQt to manage a tree view using a QAbstractItemModel. So far I have successfully implemented it such that I can load the data, expand and collapse it, and edit values. One thing I am not able to do, however, is wrap my head around inserting and removing rows. Short version of what I am trying to do: When the user edits a particular cell, I need to actually delete the underlying item in my object hierarchy and replace it with a different one. I implement this in the setData method