Questions tagged [qtreewidget]

QTreeWidget is a class in Qt that provides a tree-like view of data.

This class uses a standard model to hold items, each of them being a QTreeWidgetItem.

Before adding data into the widget, a column count must be specified with setColumnCount() function. The widget can also have a header with a section for each of the columns. It also supports column-based sorting.

A simple example of using this class looks like this:

 //creating a widget
 QTreeWidget *myTreeWidget = new QTreeWidget();
 //adding a column to it
 myTreeWidget->setColumnCount(1);
 //creating a container to temporarily hold the items
 QList<QTreeWidgetItem *> itemList;
 //filling the container with items
 for (int i = 0; i < 10; ++i)
     itemList.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("item: %1").arg(i))));
 //finally, setting the items into the widget.
 myTreeWidget->insertTopLevelItems(0, itemList);

Official documentation can be found here for Qt 4.8 and here for Qt 5.

529 questions
1
vote
1 answer

How do I sort sort a QTreeWidget or QTableWidget by multiple columns (and how do I sort these columns as numerical values)?

Suppose I have a QTreeWidget with three columns. Two of which with string values and a third with integral values, all of which may appear more than once in each column. Username (str) Product (str) Quantity (int) I then want to be able to sort…
darxtR
  • 31
  • 8
1
vote
1 answer

Drag Drop Operation in QTreeWidget not copying the dropped item

I want to copy an item from a QTreeWidget-parent under another parent via a drag & drop mouse operation. For this, I have implemented the dropEvent() and am setting the dropAction to Qt.CopyAction. But anyway, the item I am dropping is not being…
ProfP30
  • 358
  • 3
  • 18
1
vote
1 answer

how to add color animation to QTreeWidgetItem?

I need to add color animation to QTreeWidgetItem, but in my code, it raise some error, can anyone help me? The code sample is here: class TreeWigetItem(QTreeWidgetItem): def __init__(self, parent=None): super().__init__(parent) …
jett chen
  • 1,067
  • 16
  • 33
1
vote
1 answer

Derive and set color to the index of newly-added children

I have created subclass of QTreeWidget and QTreeWidgetItem where I am trying to highlight the new added items (where the text will be colored red). The tree hierarchy that I have adopted is as follows: |-- parent |--|-- child |--|-- child The tree…
dissidia
  • 1,531
  • 3
  • 23
  • 53
1
vote
1 answer

How to make editable value in QTreeWidget

I have a project. I work on json file. I got a sort in python. This is TreeView and I want to make changes to the TreeView. How do i editable it every cell. import json from PyQt5.QtWidgets import * class ViewTree(QTreeWidget): def…
sercanot
  • 25
  • 1
  • 6
1
vote
1 answer

Fix selected item highlighter on QTreeWidget

I have a QTreeWidget that has values in them, which I only want to show a certain number of decimals but keep the precision for calculation purposes. I have it working correctly, but the highlighting of the selected items are messed up and show…
Drees
  • 688
  • 1
  • 6
  • 21
1
vote
1 answer

How to alternate empty space color in QTreeWidget?

If I type this code myTree->setAlternatingRowColors(true); myTree->setStyleSheet("QTreeWidget{alternate-background-color: red;background: green;}"); colors of rows are interleaves. But if a QTreeWidget is not full there is an empty space which has…
Arseniy
  • 266
  • 2
  • 14
1
vote
1 answer

QTreeWidgetItem with two parents

Can I somehow attach one QTreeWidgetItem to two (or more) nodes at once? Just like this: parent1 └child1 parent2 └child1 If I just do addChild() on both parents, the child appears only on the first parent. Is that even possible? Or such result…
garbart
  • 465
  • 4
  • 19
1
vote
1 answer

How to keep the size of second column of a QtreeWidget (with more than 2 columns) dynamic?

I have a mainwindow with Qtreewidget(having 3 columns) as central widget. I want to keep the size of first and second column fixed, but the size of second column should be equal to the size of qtreewidget minus the size of other two columns. Since…
annie5
  • 37
  • 4
1
vote
1 answer

How to align the text in qtreewidget column in this manner : "...qtreewidgetitemdata" instead of "qtreewidgetitemdata..."?

How to align data in column 1 of qtreewidget in this manner: |Column1 |Column2| |+...abcd|efgh | |+...ijkl|mnop | instead of |Column1 |Column2| |+xyab...|efgh | |+pqij...|mnop |
annie5
  • 37
  • 4
1
vote
1 answer

How to get QTreeWidgetItem position?

How shall I get a QTreeWidgetItem LeftTop position (in pixel) after I get this item with the itemAt? Is there a simple way?
Arseniy
  • 266
  • 2
  • 14
1
vote
1 answer

How to focus the particular line edit in qtreewidget

This program i already posted i don't want to repeat the duplicate question but in this i added widget to child widget, before my all functionalities are working good,When i add the widget i faced some problem in this program i tried in different…
gowthami
  • 239
  • 2
  • 13
1
vote
0 answers

Unable to add items in the QTreeWidget

I am trying to implement QTreeWidget in my application. I am having problem in adding items in the QTreeWidget. The code below only display the number of columns in the tree (see the image below) but not the items that I have added. Could anybody…
user1703942
  • 317
  • 3
  • 15
1
vote
1 answer

How to search a item name in tree view using with pyqt4

Here it is my sample program i want to search a item in tree view,when i click a search button that item only i want to display display in scroll area, i don't have idea about it.But i tried with model and set sorted method but it can't work.can any…
gowthami
  • 239
  • 2
  • 13
1
vote
1 answer

How to remove dotted branches in Qtreewidget

I wish to remove dotted branches in Qtreewidget (QT C++). But the problem is if I use setStyleSheet(QString("QTreeView::branch{background:palette(base)}")); the + and - symbols, used for expansion and collapsing, also disappear. Original tree…
annie5
  • 37
  • 4