Iterate over expanded nodes of QTreeWidget - qt

I have a QTreeWidget. Have to iterate through the nodes which are expanded. Tried with iterating with QTreeWidgetItemIterator it(<rootNode>, QTreeWidgetItemIterator::NotHidden). But it is giving all the nodes of the tree instead of just expanded ones.
Am I missing to set any flag in the iterator?

I am afraid there is no specific flag for expanded items (but you can get checked items, for instance, using flags, http://doc.qt.io/qt-4.8/qtreewidgetitemiterator.html).
But you can easily check if item is expanded or not while iterating, using QTreeWidgetItem::isExpanded()

Related

What is the purpose of TreeView.isTreeNode

The TreeView attaches some properties to its delegate. One of them is isTreeNode. The documentation writes about isTreeNode:
required property bool isTreeNode - Is true if the delegate item represents a node in the tree. Only one
column in the view will be used to draw the tree, and therefore, only
delegate items in that column will have this property set to true. A
node in the tree should typically be indented according to its depth,
and show an indicator if hasChildren is true. Delegate items in other
columns will have this property set to false, and will show data from
the remaining columns in the model (and typically not be indented).
What is the benefit of this property? For me it looks like an alias for column == 0.
It's currently an alias for column === 0, like you say. But it makes the delegate more readable, and opens up for the possibility to rearrange columns at a later point, and improve the support for right-to-left layouts.

Keep QTreeView sorted

I have a QTreeView with 3 columns. After I remove an element from the tree model I use the following to try to keep it sorted:
sort(0, Qt::AscendingOrder);
I expected that would re-sort the whole tree using column 0 as the sorting key. However it's behaving weird, nodes appear repeated, etc. after that sort is executed. What's wrong?
What's the way to keep it sorted all the time?

Qt error "persistent model indexes corrupted" why?

I've a problem with my Qt/interview application. I use QTreeView to display tree data. I implemented my own model based on QAbstractItemModel.
I get a following error prior to application crash. It happens often after I add new record.
Could You explain to me what is the meaning of this error. What is a QPersistentModelIndex ?
I'm not using QPersistentModelIndex in my code.
ASSERT failure in QPersistentModelIndex::~QPersistentModelIndex: "persistent model indexes corrupted"
Thanks.
QPersistentModelIndexes are (row, column, parent) references to items that are automatically updated when the referenced items are moved inside the model, unlike regular QModelIndex. For instance, if you insert one row, all existing persistent indexes positioned below the insertion point will have their row property incremented by one.
You may not use them directly, but QTreeView does, to keep track of expanded items and selected items, for example.
And for these persistent indexes to be updated, you have to call the functions QAbstractitemModel::beginInsertRows() and endInsertRows() around the actual row insertion(s) when you add new records.
See the end of the section about subclassing model classes for details: http://doc.trolltech.com/latest/qabstractitemmodel.html#subclassing
I found this method QAbstractItemModel::persistentIndexList and I'm
wondering what indexes it should return. All of them ?
Should this method return all nodes currently visible in the TreeView ?
That method returns only the indexes for which a QPersistentIndexModel was created and is still in scope (as a local variable, a class member, or in a QList<QPersistentIndexModel> for example).
Expanded or selected nodes are not necessarily currently visible, so you can't (and shouldn't anyway) assume anything about what these persistent indexes are used for.
You just have to keep them updated, and you only need to use persistentIndexList for big changes in the model, like sorting (see QTreeWidget internal model : QTreeModel::ensureSorted(link)), for smaller incremental changes you have all the beginXxxRows/beginXxxColumns and endXxxRows/endXxxColumns methods.

Find Duplicates from tree list in Dev-Ex

I have a Dev-Ex Tree List which has two columns, List contains elements inside it, Now My question is if i want to add any new item in the list then logic should search existing items in the tree, if no match found then it should allow to add that item in the list,otherwise not.
can i make a method which keep on checking recursively new item with the other item in the list.
Such tasks are usually solved by using TreeList Iterator. I think that the How to Implement an Iterator for the XtraTreeList (FindNode Example) knowledge base article contains the code you are looking for.

In Flex, how do wrap Lists into columns?

How do you make a List control wrap around to a second column (or multiple columns)? Thanks, let me know if there is a solution for this with the List control or some other Flex control.
For example, if you have one list with 42 items in it, but I want to cap the height of a list to 20 items; then instead of having one list with 42 items all the way down, I would have that list of items look like the equivalent of 3 adjacent lists: the first with 20 items, the second with 20 items, and the third with 2 items (which represent the original list of 42 items).
This question seems similar but it is in ColdFusion:
Wrapping lists into columns
Using a TileList and changing the direction variable is the best solution I have come up with.
You could use a Repeater and a simple Label based itemRenderer for the list items and avoid using a list completely. If you wrap it all up inside a custom control you can provide the same API as List so your consumers will never tell the difference.
I think you're looking for a second row, as others have noted. Either setting the wordWrap to true or using a different item renderer are the best way to get it done, but using a custom item renderer will give you more control over how the object is displayed.
I suggest creating a custom Component that wraps a variable number of Lists. This custom component can have a property named "maxListHeight". It can also have a "dataProvider" property. This custom component will produce a set of horizontally aligned lists. The number of lists produced by the custom component will be: floor(dataProvider.length/maxListHeight)+1. Where all but the last list produced will have a listHeight of maxListHeight; the last list produced will have a listHeight of: dataProvider.length % maxListHeight.
This should work but managing the addition and removal of items to the masterList should require some extra work (if it is not appended/removed from the back). This would also require instantiating multiple lists instead of just one.
The default itemRenderer for a List control is TextInput that supports only single line text. Use TextArea instead.
<mx:List itemRenderer="mx.controls.TextArea"/>
Try setting the following two properties on List:
wordWrap=true
variableRowHeight=true

Resources