Navigation

    Qt Forum

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

    • SOLVED Scroll to item in TreeView, positionViewAtIndex seems not work
      QML and Qt Quick • treeview scrollto • • xiaowang  

      2
      0
      Votes
      2
      Posts
      44
      Views

      It should be used as following: __listView.positionViewAtIndex(treeView.currentIndex.row, treeView.Beginning) And it works when the treeview's length is enough long.
    • UNSOLVED scroll horizontal and vertical for a very large rectangle
      QML and Qt Quick • treeview • • lawrence.emke  

      3
      0
      Votes
      3
      Posts
      36
      Views

      @lawrence-emke hi, i think what you need is QML Flickable type Window { visible: true width: 640 height: 480 title: qsTr("Hello World") Flickable { width: 400; height: 400 contentWidth: gameBoard.width; contentHeight: gameBoard.height clip: true ScrollBar.horizontal: ScrollBar { active: true} ScrollBar.vertical: ScrollBar { active: true} Rectangle{ id: gameBoard height: 2000 width: 2000 color: "grey" Repeater{ model: 10 Drag.active: dragMouse.drag.active Rectangle{ height: 80;width: 80 x : width * index y : height * index color: Qt.rgba(Math.random(),Math.random(),Math.random(),1) MouseArea{ id:dragMouse anchors.fill: parent drag.target: parent } } } } } }
    • UNSOLVED Filtring TreeView QML
      QML and Qt Quick • qml treeview qtcpp filtring • • ENSAO_CHEIKH  

      8
      0
      Votes
      8
      Posts
      91
      Views

      @SGaist thanks a lots for your reply, bu how to do it?
    • SOLVED How to make a Text wrap delegate use the treeviews stylesheet
      General and Desktop • stylesheet treeview qstyleditemdele • • sailord  

      6
      0
      Votes
      6
      Posts
      51
      Views

      @sailord So it did use SizeHint but it was just returning too small value ? Super :)
    • UNSOLVED Nested List View in QML
      QML and Qt Quick • qml treeview ui design treemodel • • Sudip Ghimire  

      1
      0
      Votes
      1
      Posts
      42
      Views

      No one has replied

    • UNSOLVED Hide or unhide a section in QTreeView/Model
      General and Desktop • treeview mvc • • Rizwan94  

      7
      0
      Votes
      7
      Posts
      477
      Views

      Hello, Thanks a lot for the replies. I found out another way by which we can hide the 'section' if the parent doesn't have any childrens. ui.treeView->setRowHidden(parentRow, rootIndex, true) In my example, Fruits - ............Apple ............Orange Animals - .............Lion .............Tiger Colors - ............Red ............Green ............BLue Fruits is 0th parent Animals is 1st parent Colors is the 2nd parent So whenever any of the children's are missing ( which we come to know while filling up the model ), I am setting the respective "parent" row as hidden. This approach worked fine and as expected. Is anything wrong with this approach? Model remains the same, only the view is hidden or unhidden based on some condition. Please Let me know.
    • UNSOLVED QItemSelection::merge() is really slow
      QML and Qt Quick • treeview quick controls selectionmodel • • andreh  

      1
      1
      Votes
      1
      Posts
      173
      Views

      No one has replied

    • SOLVED TreeView “cursor” without focus?
      General and Desktop • treeview focus cursor currentindex qabstractitemvi • • -DLF-  

      10
      0
      Votes
      10
      Posts
      1105
      Views

      Hi, It seems I can go with the solution I described. I don't need the tree view to be focused, so I just removed the “focus rect” (if that is the name Qt people know ;)) by setting the focus policy of the tree to Qt.NoFocus. I draw the “cursor” then myself by giving a different backlog in QAbstractItemModel::data. That makes anyway sense since the cursor position is part of my domain model. Thanks for help and inspiration! Dan
    • SOLVED Implement QSortFilterProxyModel with own TreeModel?
      General and Desktop • treeview qsortfilterprox sort treemodel • • Opa114  

      11
      0
      Votes
      11
      Posts
      912
      Views

      @VRonin said in Implement QSortFilterProxyModel with own TreeModel?: Good guess, can you show us your code? I solved it: I had to pass the parent index (tree structure), so the line should look like this: QVariant data = m_proxy->data(m_proxy->index(index.row(), 4, index.parent()));
    • UNSOLVED Drag&Drop between Treeviews replaces target item
      General and Desktop • treeview drag&drop • • flautzr  

      2
      0
      Votes
      2
      Posts
      333
      Views

      Hi and welcome to devnet, What version of Qt are you using ? On what OS ? With what compiler ? Can you provide a minimal compilable example that shows that behaviour ?
    • UNSOLVED Drag and Drop in QML TreeView with multiselection
      QML and Qt Quick • drag and drop treeview selection item delegate • • T-Man  

      2
      0
      Votes
      2
      Posts
      1495
      Views

      By adding the line "property alias mouser: mouseArea" to the TreeView.qml of Qt, I can implement mouser.onPressed: {...} inside my TreeView code. This way both the selection and drag&drop work, but I actually don't like the idea of modifying Qt code. No one out there with an approach how to solve this a bit cleaner?
    • UNSOLVED Implementing Drag and Drop with QTreeView
      General and Desktop • model-view drag and drop treeview itemmodel • • jonasqt  

      1
      0
      Votes
      1
      Posts
      2042
      Views

      No one has replied

    • SOLVED How to retrieve items indices from a treeView?
      QML and Qt Quick • qml model-view treeview index delegates • • Haitham  

      11
      0
      Votes
      11
      Posts
      4949
      Views

      @VRonin Can you please provide an example or something to follow? Because I am still a newbie at both Qt and QML. Sorry for bothering you with my many questions. Update: as you can see in the code, I change the state of the delegate through the mouse area in the delegate (it's commented out in the code). I was using it to test the states, now I've noticed another thing; Whenever I collapse the parent Item and then expand it, the previous states are not saved....does this have to do anything with what you mentioned?
    • UNSOLVED Drag & drop in QTreeWidget
      General and Desktop • treeview drag&drop treemodel treewidget • • Maluna34  

      7
      0
      Votes
      7
      Posts
      6432
      Views

      The best way seems to use QDropEvent::source to get the QTreeWidget and use currentItem() on it. :)
    • UNSOLVED QML TreeView - how to apply delegate to certain items in the tree?
      QML and Qt Quick • qml model-view delegate treeview • • Haitham  

      9
      0
      Votes
      9
      Posts
      6776
      Views

      @6thC did your application consist of a tree and you could apply a delegate to specific items? because that's where I'm stuck now. I am still researching on how to connect QML with C++ and as usual if I figured out a way of applying delegates to specific items based on a logical condition (like your warning and maximum states), I will let you know. Thanks for your time bro!
    • SOLVED TreeView Hide Column hides the expand / collapse icon and prints plain Table
      General and Desktop • treeview icon column expand symbol • • Opa114  

      3
      0
      Votes
      3
      Posts
      1322
      Views

      Good to know, so my solution to store this in the last column and hide this one is the best solution for me.
    • 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
      2688
      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 Qt nested ListView or can I use TreeView
      QML and Qt Quick • qml c++ listview treeview • • CocoJoe  

      4
      0
      Votes
      4
      Posts
      3459
      Views

      @CocoJoe Welcome. You can answer on stackoverflow)
    • UNSOLVED Tips to start to work with mysql
      General and Desktop • database mysql treeview • • WarOfDevil  

      6
      0
      Votes
      6
      Posts
      1972
      Views

      For a beginner I have found Youtube tutorials from VoidRealms very helpful. For example this tutorial is about editing in a database table: https://www.youtube.com/watch?v=LkbfNoZrTBQ&list=PL2D1942A4688E9D63&index=56 (C++ Qt 56 - QSqlTableModel )
    • SOLVED QTreeView shows all the subfolders, but not the parent folder.
      General and Desktop • treeview qt 5.6 qfilesystemmode directory root • • Punit  

      7
      0
      Votes
      7
      Posts
      3656
      Views

      I had issues making these solutions work for the QML TreeView. I ended up setting the root path of my QFileSystemModel to the directory I wanted to view. Then I set the rootIndex in the TreeView to the parent of the index for that directory. This is of course showed its siblings. Then I did the following to filter those siblings away. I also made this optional through a property as there are times when I want that behavior: bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { FileSystemModel* tmodel = qobject_cast<FileSystemModel*>(parent()); if(tmodel){ QModelIndex index = tmodel->index(source_row, 0, source_parent); QModelIndex rootIndex = tmodel->index(tmodel->rootPath()); if(!rootIndex.isValid() || !index.isValid()) return false; return ((index == rootIndex) || !(tmodel->filtersiblings() && isSiblingOf(index, rootIndex))); } return false; } bool isSiblingOf(const QModelIndex& index, const QModelIndex& parent) const { if(!index.isValid() || !parent.isValid()) return false; QModelIndex sibling; int row=0; do{ sibling = parent.sibling(row,0); if(sibling == index) return true; ++row; }while(sibling.isValid()); return false; } I took more of a blacklist approach versus a whitelist approach.
    • SOLVED QStandardItemModel appendRow doesn't update QML TreeView
      General and Desktop • qt quick model treeview • • BitteWenden  

      24
      0
      Votes
      24
      Posts
      6997
      Views

      Sneaky one ! Glad you found out :)
    • UNSOLVED Setting the column size and color of TreeView
      QML and Qt Quick • qtquick treeview • • BitteWenden  

      1
      0
      Votes
      1
      Posts
      417
      Views

      No one has replied

    • UNSOLVED How to save a treeview as .csv file in Qt?
      General and Desktop • treeview file save • • fbengo  

      5
      0
      Votes
      5
      Posts
      3078
      Views

      @fbengo oops..sry my bad. but as i said... straight from my head :) just adapt the starting method: void someFunction() { QFile file(filePath); if (file.open(QFile::WriteOnly)) { QTextStream stream(&file); for (int r = 0; r < model->rowCount(); r++) this->printTree( 0, model->index(r,0), stream ); file.close(); } }
    • SOLVED Need help with populating QML TreeView
      General and Desktop • treeview • • infinicat  

      3
      0
      Votes
      3
      Posts
      1272
      Views

      Thank you. That worked.
    • TreeView parent to child link in view field
      QML and Qt Quick • qml treeview • • Rahul_Singh  

      5
      0
      Votes
      5
      Posts
      2344
      Views

      @Citron Thanks for you reply.. i have done it. import QtQuick 2.5 import QtQuick.Controls 1.4 as QControls import QtQuick.Controls.Styles 1.4 import OrmcoUI.Controls 1.0 TreeViewStyle{id: styleId; backgroundColor: "transparent" indentation: 20 itemDelegate: checkBoxDelegate; branchDelegate: branchDelegateId property variant linkDepthArray:[0] property int linkWidth: 0 property int linkHeight: 0 property color linkColor: "#5F5F5F" Component {id: branchDelegateId Item {id: branchItemId; x: -5; width: 12; height: 12; Rectangle {anchors.fill: parent; color: "transparent"; Image{anchors.fill : parent source: styleData.isExpanded ? "qrc:/minus.png" : "qrc:/plus.png" } Component.onCompleted: { linkDepthArray[styleData.depth] = x - width; linkWidth = width; linkHeight = height; } } } } Component { id: checkBoxDelegate Item { GQITreeViewItem{anchors.fill: parent; branchHeight: linkHeight; branchWidth: linkWidth; treeModel: control.model; depthArray: linkDepthArray; index: styleData.index; widthOffset: indentation } } } // Component { // id: checkBoxDelegate // Item { // id: container; // property int offset: (height - branchHeight) / 2.0 // GQICheckBox{id: checkBox; anchors.verticalCenter : container.verticalCenter // checkedState: styleData.value; // text: control.model.GetText(styleData.index); // onClicked: // { // console.log("value", styleData.value) // console.log("Checked index", styleData.index) // control.model.SetData(checked, styleData.index); // } // Component.onCompleted: { // updateLine(control.model.GetDepth(styleData.index)); // //console.log("Checked height", container.height) // } // } // property Item rectItem // function updateLine(depth){ // for (var i=0; i<depth; i++){ // var posX = depthArray[i] - (i+1) * indentation // var drawLine = true; // if(i > 0 && control.model.IsLastElement(styleData.index, i)) // drawLine = false; // if(drawLine) // { // rectItem = linkComponentId.createObject(container); // rectItem.x = posX; rectItem.height = (i+1) * container.height; // if(control.model.IsFirstElement(styleData.index)){ // rectItem.y = -offset; rectItem.height += offset; // } // //to restrict height of rectangle // if(control.model.IsLastElement(styleData.index)) // rectItem.height = (rectItem.height - rectItem.y) / 2.0; // } // if(i == 0){ // rectItem = linkComponentId.createObject(container); // rectItem.x = posX; rectItem.width = container.x - posX - 5; // rectItem.height = 1; rectItem.y = container.height / 2.0; // if(control.model.IsParentNode(styleData.index)) // rectItem.width = indentation - (branchWidth / 2.0) + 2; // } // } // } // Component {id: linkComponentId // Item {id: linkRectId; // width: 1; height: container.height; // Rectangle{ // anchors.fill: parent; // color: linkColor; // } // } // } // } // } }
    • QtCreator не видит TreeView
      Russian • qml qtcreator treeview controls 1.4 cant see • • Locky  

      1
      0
      Votes
      1
      Posts
      788
      Views

      No one has replied

    • change "+" symbol to other symbol when dragging an item from listview to treeview .
      General and Desktop • listview treeview • • Ratzz  

      22
      0
      Votes
      22
      Posts
      6270
      Views

      I used dragMoveEvent to restrict the + symbol. void dragMoveEvent(QDragMoveEvent *event) { QPoint cursorPosition = event->pos() ; QModelIndex index = indexAt(cursorPosition); if(index.parent().isValid()) { event->acceptProposedAction(); } else event->ignore(); }
    • [SOLVED]How to delete an item from the treeview by droping an item to pushbutton or to an group box
      General and Desktop • drag and drop treeview • • Ratzz  

      54
      0
      Votes
      54
      Posts
      14572
      Views

      @mrjj cheating works fine :)
    • TreeView's item delegate receiving empty strings as styleData.value
      QML and Qt Quick • treeview • • Citron  

      1
      0
      Votes
      1
      Posts
      655
      Views

      No one has replied

    • Select only item in TreeView
      QML and Qt Quick • qml treeview • • Rutra  

      1
      0
      Votes
      1
      Posts
      585
      Views

      No one has replied

    • [Solved] Scroll to item in TreeView
      QML and Qt Quick • qml treeview scrolling • • Precitec  

      2
      0
      Votes
      2
      Posts
      2582
      Views

      @Precitec Managed it myself. Found code in TableView source i could use for TreeView: function positionViewAtRow(row, mode) { __listView.positionViewAtIndex(row, mode) }
    • How to check elements whether it exists or not after drag and drop operation?
      General and Desktop • drag and drop treeview • • ankit thakar  

      2
      0
      Votes
      2
      Posts
      763
      Views

      Hi, You should be able to do it on the drop event. There you can check whether you already have an element corresponding to what is being dropped and you can use a QDialog to ask the question to your user. Hope it helps
    • TableViewColumn displaying data based on two roles (TreeView)
      General and Desktop • qml model-view treeview qstandarditem role • • BPie  

      1
      0
      Votes
      1
      Posts
      575
      Views

      No one has replied

    • QAbstractItemModel + QML5.5 TreeView
      QML and Qt Quick • treeview qabstractitemmo • • Valerian  

      2
      0
      Votes
      2
      Posts
      1405
      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) } }
    • Changing view's model crashes at some point
      QML and Qt Quick • listview crash bug treeview • • Pheelbert  

      2
      0
      Votes
      2
      Posts
      885
      Views

      Nevermind I found a solution: QQmlApplicationEngine::setObjectOwnership(MY_OBJECT*, QQmlApplicationEngine::CppOwnership); It's important to set this whenever returning a pointer in a Q_INVOKABLE function or else it might get garbage collected apparently.
    • [Request] TreeView C++ model to qml example
      QML and Qt Quick • qml treeview view example tree • • Pheelbert  

      4
      0
      Votes
      4
      Posts
      4862
      Views

      @Pheelbert Yes missed the mentioning of data() here. You're Welcome :-) Happy Coding.
    • [Solved] New TreeView does not connect to C++ model.
      QML and Qt Quick • qml c++ model-view qtquick2 treeview 5.5 modelview model view prog • • Kofr  

      8
      0
      Votes
      8
      Posts
      5157
      Views

      @Valerian I did not do d&d yet. In my idea you should register a signal to be emitted whenever you move mouse in the area of new position and call swap function. Do you feel something like this?
    • SetRootIndex TreeView QML
      General and Desktop • treeview 5.5 rootindex • • David Dur  

      1
      0
      Votes
      1
      Posts
      758
      Views

      No one has replied