Navigation

    Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Search
    • Unsolved
    1. Home
    2. Tags
    3. qabstractitemmo
    Log in to post

    • UNSOLVED Custom model of nested lists to QML
      General and Desktop • qml model-view qabstractitemmo qabstractlistmo • • EStudley  

      2
      0
      Votes
      2
      Posts
      103
      Views

      Still not sure what's the best design here.
    • UNSOLVED segv when getting QFileInfo from subclassed QFileSystemModel
      General and Desktop • qtableview qabstractitemmo qfilesystemmode qmodelindex qt5.13.1 • • CybeX  

      2
      0
      Votes
      2
      Posts
      140
      Views

      What's the benefit of FileSystemModel::getFileInfo()? I would guess your this pointer is a nullptr
    • SOLVED How does MQL TreeView release its resource?
      QML and Qt Quick • qabstractitemmo qml treeview beginresetmodel • • kevinguo  

      5
      0
      Votes
      5
      Posts
      192
      Views

      @sierdzio said in How does MQL TreeView release its resource?: I have a workaround: store the data and delete it at the next refresh event. In order to have more control, my final choice is to delete it manually instead of using auto pointer. But anyways, thanks for your suggestion. Kevin
    • SOLVED QSortFilterProxy & QIdentityProxyModel & QAbstractItemModel = Crash :- )
      General and Desktop • drag and drop qabstractitemmo qsortfilterprox drag&drop qidentityproxym • • Dariusz  

      26
      0
      Votes
      26
      Posts
      639
      Views

      @JKSH Yep I'm having a full run through the app now to ensure everything happens in GUI thread - that is widget/affects widget.
    • UNSOLVED QAbstractItemModel asserts & multithreading
      General and Desktop • qabstractitemmo qassert • • Dariusz  

      8
      0
      Votes
      8
      Posts
      377
      Views

      @Dariusz said in QAbstractItemModel asserts & multithreading: Hmmm I think this might not work for me Why not? It makes no difference if you push or pull the data... but it's up to you :)
    • SOLVED QAbstractItemModel - basic example
      General and Desktop • qabstractitemmo • • Dariusz  

      3
      0
      Votes
      3
      Posts
      279
      Views

      You are trying to overload the Data function by data(parent) but the real signature of this function is data(index,role) Try to replace for this sneap of code: def data(self, index, role, *args, **kwargs): if role == Qt.DisplayRole: return "hi" return None You also need to import Qt from QtCore module. #from PyQt5.QtCore import QAbstractItemModel, QModelIndex from PySide2.QtCore import QAbstractItemModel, QModelIndex, Qt
    • SOLVED QAbstractItemModel: much time lost on nothing between beginResetModel() and endResetModel()
      General and Desktop • qabstractitemmo speed tables • • Joachim W  

      10
      0
      Votes
      10
      Posts
      795
      Views

      @Joachim-W Then please mark this topic as solved, thx.
    • SOLVED QComboBox & QAbstractItemModel - editable/filtering
      General and Desktop • qcombobox qabstractitemmo • • Dariusz  

      3
      0
      Votes
      3
      Posts
      631
      Views

      @SGaist Awesome thanks! I think I can get it to do my bad biding now :- )
    • SOLVED Notifying model QSortFilterProxyModel / QIdentityProxyModel of model data change?
      General and Desktop • qabstractitemmo qsortfilterprox qdrag drag drop qidentityproxym • • Dariusz  

      3
      0
      Votes
      3
      Posts
      817
      Views

      You may also try to set dynamicSortFilter: true, but only if you do not modify contents of model through proxy model. invalidate() calls are expensive and you should only do it when you know what you are doing. If you modify contents of your model through proxy model and/or you need to filter and sort on demand, invalidateFilter() and sort() is what you are looking for.
    • SOLVED QTreeView/Model drop action - no expand sign ?
      General and Desktop • qtreeview qabstractitemmo qdrag qdrop • • Dariusz  

      3
      0
      Votes
      3
      Posts
      418
      Views

      @raven-worx said in QTreeView/Model drop action - no expand sign ?: Also did you emit the dataChanged() signal on the parent index? I've just read the post. I forgot to correct it. This is what I edit: bool testModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { ... Q_EMIT dataChanged(itemFirst.index(),itemLast.index()) } Hmmmm so I tried this, the parent is the object that is in function above. Q_EMIT dataChanged(parent, parent) Now this now "magically" works, I get extra ">" when I drop item on another item... I also learned that I also need to call Q_EMIT layoutChanged({parent}/flag) to update view if I drop items on expanded parent... Ok all good then, thanks! Weird issue o.o
    • UNSOLVED Model view widget with different root item ?
      General and Desktop • qtreeview qabstractitemmo qstandarditemmo • • Dariusz  

      9
      0
      Votes
      9
      Posts
      715
      Views

      @SGaist Woah... I have lots to read! Thanks! Gotta dig into proxier more then.
    • SOLVED Qt model/view framework selection system - store/restore selections
      General and Desktop • qabstractitemmo qitemselection • • Dariusz  

      2
      0
      Votes
      2
      Posts
      223
      Views

      @Dariusz I'm a nob. I captured selection range after action and not before. Storing selection before calling QTreeView::mouseReleaseEvent(event); seems to have solved the issue.
    • SOLVED Reimplementing QFileSystemModel Checkboxes using QMap inconsistent results
      General and Desktop • qtreeview qabstractitemmo qsortfilterprox qfilesystemmode • • moffa13  

      15
      0
      Votes
      15
      Posts
      1508
      Views

      Ok I found what was causing this awful bug. When I check if the map contains the index, I actually check the raw index not the QPersistantModelIndex so this is not the same object and I think qmap does not check equality using == operator . So I have to iterate over the map and check using QPersistantModelIndex "==" operators which can compare from a QModelIndex.
    • UNSOLVED QTreeView store expanded state - long ?
      General and Desktop • qtreeview qabstractitemmo expanded isexpanded • • Dariusz  

      2
      0
      Votes
      2
      Posts
      552
      Views

      Hey Just thoguh I'd drop a "temporary" solution I'm testing now. I ended up extending qtreeView, and capturing expand/collapse signals. Then I generate a QSet with these ids that later I can store/restore via model()->match(id) idea. Not sure how well it will work in very large data sets, say 100k items and 10k expanded state items, But well see.
    • SOLVED QFrame with layout and comboBoxes insight => setStylesSheet calls index method of QAbstractItemModel of connected comboBoxes
      General and Desktop • stylesheet performance qabstractitemmo qframe • • Dagginio  

      11
      0
      Votes
      11
      Posts
      1307
      Views

      @Dagginio Hi just call update() to have it refresh when "status" changes. -Do I have to remove that blue frame before I paint a grey one? depends if you have autofillbackground on widget on. in that case it will be cleared default. else u might have to. try without and see
    • UNSOLVED where to call beginRemoveRows() when QAbstractItemModel is deleted from somewhere else
      General and Desktop • qabstractitemmo beginremoverows • • gde23  

      6
      0
      Votes
      6
      Posts
      1244
      Views

      Not a good idea indeed. Why would the item have to know anything about what stores it ?
    • SOLVED Click on an element in GridView and invoke a function
      QML and Qt Quick • qabstractitemmo gridview onclicked • • MoaMoaK  

      2
      0
      Votes
      2
      Posts
      1535
      Views

      Please do not double-post. I'm closing this one.
    • UNSOLVED QTreeView - Hide controls for expanding and collapsing specific items
      General and Desktop • qtreeview qabstractitemmo • • pablo_worker  

      3
      0
      Votes
      3
      Posts
      3154
      Views

      rather than the delegate I'd reimplement QTreeView: protected: virtual void drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const virtual void drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const and slots void collapse(const QModelIndex &index) void expand(const QModelIndex &index) But agree is not straightforward and will require some work
    • UNSOLVED QAbstractItemModel with QtQuick: Column is always 0 in the index
      QML and Qt Quick • qml qtquick qabstractitemmo column index • • Wayne1017  

      2
      0
      Votes
      2
      Posts
      1027
      Views

      I tried to understand by reading your description. I should appreciate your patience to write this whole description. Coming to you issue, you are using model and view with View has single column. You are using the repeater. It is single column there. This requests for index with row and column=0. This is how it works always. If you are using TableView with appropriate TableModel then it will request for row and column values.
    • SOLVED Problem with QTreeView, custom tree model and proxy model
      General and Desktop • qtreeview qabstractitemmo modelview qsorfilterproxy • • YuriQ  

      6
      0
      Votes
      6
      Posts
      4067
      Views

      @michalos I'm not sure if I can help you but seems like model test code works for me. What I did: Added modeltest.h and cpp into my project Added "testlib" into "QT" section of project file Added this to modeltest.h: #include <QtTest/qtestcase.h> #define qVariantCanConvert(_type_, _var_) _var_.canConvert(QMetaType::_type_) Changed expressions like "qVariantCanConvert<QString> ( variant)" to "qVariantCanConvert(QString, variant)" in modeltest.h And... my sample model failed to pass the test of course :D
    • UNSOLVED How to add QComboBox and TextField inside TreeView with delegate QML?
      QML and Qt Quick • qml qcombobox delegate treeview qabstractitemmo • • tamlong0205  

      4
      0
      Votes
      4
      Posts
      2906
      Views

      @tamlong0205 I think most of this can be done from C++ side. You can add a function in the model which can return what type is the data for current index. This function will be called from QML and depending upon its value use a Loader to load the specific delegate. Perhaps setting currentIndex in Component.onCompleted handler ? Create a C++ function which will store in info in the model itself i.e When you change the index in ComboBox call this function and update the value there and may be maintain a role to store this update.
    • UNSOLVED Simple Tree Model derived from QAbstractItemModel inserting new Nodes?
      General and Desktop • model qabstractitemmo tree treemodel • • Opa114  

      1
      0
      Votes
      1
      Posts
      523
      Views

      No one has replied

    • UNSOLVED QAbstractItemModel: how can I associate more data with a QModelIndex than just a pointer or integer?
      General and Desktop • qabstractitemmo qmodelindex internalpointer • • Guy Gizmo  

      21
      0
      Votes
      21
      Posts
      5873
      Views

      @Guy-Gizmo said: The whole point of me setting it up that way is that the actual logical structure of the data and the physical arrangement and implementation of it are conceptually completely separate. The latter is abstracted away by the interface of the former. Then I think the cleanest solution is to have a tree (or w/e) that represents your logical structure, and that will abstract the whole physical layer. For a simple example you can look at the docs - the simple tree model. You can put anything in that tree and it's basically your "data interface". It also shouldn't care that the physical nodes are destroyed as long as there's a logical node living. This way you don't have with model indexes and things getting destroyed in the background, because it's the middleman's responsibility. You should hover take care to notify the model when a node/leaf from the "logical structure" tree is destroyed (through the appropriate signals), so views can make proper adjustments. I hope that helps somewhat. Kind regards.
    • SOLVED Can't get QColumnView to display more than one row of data with my QAbstractItemModel-derived class
      General and Desktop • qtreeview qabstractitemmo models qcolumnview • • Guy Gizmo  

      2
      0
      Votes
      2
      Posts
      751
      Views

      Someone on stackoverflow was kind enough to point out my error. My parent method() should have been: QModelIndex MyModel::parent(const QModelIndex &index) const { if (!index.isValid()) { return QModelIndex(); } QObject *item = (QObject *)index.internalPointer(); Directory *parentItem = qobject_cast<Directory *>(item->parent()); if (!parentItem || parentItem == invisibleTopLevelDirectory()) { return QModelIndex(); } Directory *parentOfParentItem = qobject_cast<Directory *>(parentItem->parent()); if (!parentOfParentItem) { return QModelIndex(); } int listIndex = parentOfParentItem->indexOfItem(parentItem); if (listIndex < 0) { return QModelIndex(); } else { return createIndex(listIndex, index.column(), parentItem); } }
    • SOLVED QAbstractItemModel with QTreeview and accessing through indexing
      General and Desktop • qtreeview qabstractitemmo qmodelindex • • Trilec  

      9
      0
      Votes
      9
      Posts
      8409
      Views

      Cool, Thanks for all the insite: I have solved the problem with a little more testing. For the sake of completeness and for others Ive included my code: void DialogStructureXML::on_btn_add_toroot_released() { QModelIndex currentIndex = ui->tree->selectionModel()->currentIndex(); QModelIndex rootIndex = ui->tree->rootIndex(); QModelIndex traceIndex = currentIndex; QModelIndex child = currentIndex; tree_model *model = (tree_model*) ui->tree->model(); int rowCount = model->rowCount(); int currentRow = 0; int prevRow = 0; //some string cleanup QString ItemText = ui->edit_textvaluefortree->text() ; ItemText.simplified(); //If its a valid index (ie: valid something in the GUI tree) trace back to the parent if ( traceIndex.isValid() ) { while ( traceIndex.isValid() ) { currentRow = traceIndex.row()+1; traceIndex = model->parent(traceIndex); } } if (!model->insertRow(currentRow, rootIndex)) return; child = model->index(currentRow, 0, rootIndex); //Column index 0 model->setData(child, QVariant( ItemText ), Qt::EditRole); return; }
    • UNSOLVED How to get Persistant delegate for single column for TreeView using AbstractItemModel
      General and Desktop • qtreeview qabstractitemmo qstyleditemdele persistent setindexwidget • • Sruthi  

      1
      0
      Votes
      1
      Posts
      939
      Views

      No one has replied

    • SOLVED QTreeView not refresh correctly
      General and Desktop • qtreeview qabstractitemmo itemmodel • • NicolasS  

      3
      0
      Votes
      3
      Posts
      2458
      Views

      @SGaist Thanks for your advise, it works like well now.
    • Make a custom view for data model or possible use ListView+Canvas?
      QML and Qt Quick • listview qabstractitemmo canvas • • sigmaN  

      4
      0
      Votes
      4
      Posts
      2703
      Views

      @sigmaN AFAIK there is no ready-made method for it. You can try digging up the source and particularly the delegate part of it only in which these roles are available. Apart from that there is another way to access the data. Iterating through the children of ListView's contentItem as all the items (delegate too) declared inside ListView are parented to it. But IMO it is not a recommended way.
    • QComboBox with QAbstractItemModel, default text problem
      General and Desktop • qcombobox qabstractitemmo • • applefier  

      10
      1
      Votes
      10
      Posts
      2342
      Views

      @Michael-Scopchanov said in QComboBox with QAbstractItemModel, default text problem: "I would be glad to" is considered a polite form of speech. Provide some minimal example or code if you expect someone to look at it, comment and try to help you. This kind of arguing does not, nor is going to, get you anywhere. PS. Notice I didn't use "please", "would you", "be so kind as to" etc., because these words have no meaning in a technical discussion. We want facts and well structured problems to take a stab at and have some fun, and you want answers; it's a symbiosis and we don't get paid for our time. So unless someone's been openly hostile or have shown malice, which nobody had, then just as a friendly advice you'd do yourself good to grow some thicker skin.
    • [Solved] beginRemoveRows() with an unknown amount of rows
      General and Desktop • qabstractitemmo • • Joel Bodenmann  

      5
      0
      Votes
      5
      Posts
      3484
      Views

      @Chris-Kawa Oh, now i understand. Well, this makes a lot of sense. Thank you for your help, very appreciated!
    • How to serialize QAbstractItemModel in QDataStream?
      General and Desktop • qabstractitemmo mvc serialization qdatastream • • Ralf  

      2
      0
      Votes
      2
      Posts
      1307
      Views

      Hi, There's no ready made code to dump your model since only you know what make sense to dump. So yes you'll have to write the dumper and loader yourself. QDataStream comes to mind for that task. Hope it helps
    • [Solved] QAbstractItemModel parent() implementation
      General and Desktop • qtreeview qabstractitemmo parent • • Joel Bodenmann  

      21
      0
      Votes
      21
      Posts
      7426
      Views

      In order to be future-proof I implemented the abstract node based concept as suggested by @Chris-Kawa and @Harb (in the first post). Everything is working nicely. Thanks for your help!
    • QAbstractItemModel + QML5.5 TreeView
      QML and Qt Quick • treeview qabstractitemmo • • Valerian  

      2
      0
      Votes
      2
      Posts
      1480
      Views

      Here's the code class TreeModel : public QAbstractItemModel { Q_OBJECT public: explicit TreeModel(const QString &data, QObject *parent = 0); ~TreeModel(); enum TreeRoles { TitleRole = Qt::UserRole + 1, SummaryRole }; QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE; bool setData(const QModelIndex &index, const QVariant &value, int role); Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE; int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; protected: QHash<int, QByteArray> roleNames() const; private: TreeItem *rootItem; }; here's the code of the TreeView TreeView { id: view anchors.fill: parent anchors.margins: 2 * 12 + row.height model: treeModel selection: selectionModel headerVisible: false itemDelegate: Component { id: dragDelegate MouseArea { id: dragArea property bool held: false height: content.height drag.target: held ? content : undefined drag.axis: Drag.YAxis onPressAndHold: held = true onReleased: held = false Rectangle { id: content anchors { horizontalCenter: parent.horizontalCenter verticalCenter: parent.verticalCenter } width: dragArea.width height: 20 Text{ anchors.verticalCenter: parent.verticalCenter text: styleData.value } border.width: 1 border.color: "lightsteelblue" color: dragArea.held ? "lightsteelblue" : "green" Behavior on color { ColorAnimation { duration: 100 } } radius: 2 states: State { when: dragArea.held ParentChange { target: content; parent: root } AnchorChanges { target: content anchors { horizontalCenter: undefined; verticalCenter: undefined } } } } } } TableViewColumn { title: "Name" role: "Title" resizable: true } onClicked: { console.log("clicked", index) } onDoubleClicked: { console.log("double clicked " + index) clickedIndex = index console.log("DoubleClickedIndex " + clickedIndex) textEditRect.visible = true; textEdit.text = fileSystemModel.data(index, "Title") textEditRect.forceActiveFocus() isExpanded(index) ? collapse(index) : expand(index) } }
    • MapItemView is not updating upon model dataChanged signals
      QML and Qt Quick • qml qabstractitemmo location mapitemview datachanged • • Charby  

      2
      0
      Votes
      2
      Posts
      1628
      Views

      Has any one experienced the same problem ? Any idea of a possible workaround ? Thanks for your help.
    • QML AbstractItemModel access by Row and Role
      QML and Qt Quick • qabstractitemmo role • • Richard15  

      4
      0
      Votes
      4
      Posts
      6269
      Views

      @t3685 As stated in the OP, I know I can write specific getter/setter methods into my QAbstractItemModel subclasses. However, if that really was the only option then QML would be effectively useless for nontrivial data-driven applications as the data models cease to be a standard interface. @p3c0 Thanks, I hadn't thought of doing it that way. In Qt 5.4 you can do this if you set Q_INVOKABLE on QAbstractItemModel::index(int row, int column, const QModelIndex &parent) and QAbstractItemModel::data(const QModelIndex &index, int role) methods. I'm guessing this has been done for you in Qt 5.5. I have also found that in Qt 5.4 (and presumably 5.5) it's also possible to get there via a DelegateModel (often called a VisualDataModel in the documentation), as the DelegateModelGroup within that has a get(row) function that returns an Object through which you can access the data in the same way as in a QML Delegate. http://doc.qt.io/qt-5.4/qml-qtqml-models-delegatemodelgroup.html#get-method However, I haven't yet figured out when it reads the data from the underlying model. Thus, if the DelegateModel has only the default DelegateModelGroup: myDelegateModel.items.get(%row%).model.%role_name% In this, myDelegateModel is a DelegateModel object (which may also be used as the model in a ListView, GridView or PathView), %row% is the row number and %role_name% is the role. Set myDelegateModel.rootIndex to the appropriate parent QModelIndex. PS: $Deity the documentation is beyond awful. So many links straight back to exactly where you are masquerading as a link to what the thing is.
    • synchronize two QabstractItemModel on Single Common Column
      General and Desktop • qwidget qtableview qabstractitemmo qheaderview qwindow sorting custom item • • Zee_07  

      1
      0
      Votes
      1
      Posts
      541
      Views

      No one has replied

    • How to ensure all models updated before accepting a QDialog
      General and Desktop • qdialog qabstractitemmo • • bsomervi  

      2
      0
      Votes
      2
      Posts
      1033
      Views

      Something like this should do the trick: void MyDialog::accept() { stuff->setFocus(); //to move focus away from the table or any delegate if( /* do any data validation */) QDialog::accept(); //call base implementation only if everything is ok }