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
18
votes
3 answers

How to create delegate for QTreeWidget?

Here is what I'm trying to do (all parents and children must have a close button on the right, in the future, only the hovered item will be able to show the **close ** button): My delegate code: class CloseButton : public QItemDelegate { …
mosg
  • 12,041
  • 12
  • 65
  • 87
16
votes
2 answers

What is the method to set the text for a QTreeWidget's header?

I've checked the documentation here and I can't seem to find a method for setting the text of a QTreeWidget's title or header. Without setting the title QTreeWidget automatically uses the number '1' in my code. An example of what it looks like…
Robert Whitley
  • 1,051
  • 5
  • 14
  • 28
15
votes
1 answer

QTreeView or QTreeWidget

I want to implement in my program a tree with nested sub-levels, and I'm looking for which of those two kind(View/Widget) is best suited for my goal. I have a list of days with task that are either done/missed/failed, each task has a count of how…
f.rodrigues
  • 3,499
  • 6
  • 26
  • 62
14
votes
2 answers

How to resize columns in QTreeWidget to the minimum space required

I am a student programmer and I am using Qt to build a GUI interface for work. I have a QTreeWidget that has a total of 8 Columns. The input that needs to be entered into each one of these columns is fairly small. In that regard, I was trying to…
Wylie Coyote SG.
  • 1,009
  • 6
  • 22
  • 37
14
votes
2 answers

Multiple Selection QTreeWidget

Does anyone know if its possible to select multiple items on a QTreeWidget and how to go about enabling the multiple selection? All the items I want to be selectable are top level QTreeWidgetItems and all their children are set to be disabled (i.e…
Jay
  • 3,373
  • 6
  • 38
  • 55
14
votes
1 answer

How to automatically sort a QTreeWidget column?

I'm using a QTreeWidget to display some simple items. I've set the list sortable by .setSortingEnabled(true) calling. In this way, the list is sorted only when the user press the title column, and not automatically whenever new item is inserted. Is…
Emilio
  • 3,901
  • 11
  • 44
  • 50
14
votes
2 answers

Delete QTreeWidgetItem in PyQt?

I'm finding it frustratingly hard to find a simple way to delete my selected QTreeWidgetItem. My patchwork method involves setting the tree's current selection to current and then: if current.parent() is not None: …
RodericDay
  • 1,266
  • 4
  • 20
  • 35
12
votes
2 answers

Slow selection in QTreeView, why?

I've recently hit a wall in a project I'm working on which uses PyQt. I have a QTreeView hooked up to a QAbstractItemModel which typically has thousands of nodes in it. So far, it works alright, but I realized today that selecting a lot of nodes is…
Virgil Dupras
  • 2,634
  • 20
  • 22
12
votes
4 answers

QTreeWidget right click menu

I looked around and it seems that the problem is present not only for tree widget but also for other widgets. But in my case, I found a solution, although an incomplete one. I am adding actions to my tree widget, so that when you right click on it,…
ISTB
  • 1,799
  • 3
  • 22
  • 31
12
votes
4 answers

How to delete QTreeWidgetItem

Several webpages say that QTreeWidgetItem can be deleted by deleting or QTreeWidget.clearing. But my code sample below doesn't seem to do so. Am I doing anything wrong? #!/usr/bin/python import sys from PySide.QtGui import QApplication, QWidget,…
IsaacS
  • 3,551
  • 6
  • 39
  • 61
11
votes
3 answers

Getting a QTreeWidgetItem List again from QTreeWidget

How do i do that? Actually my main goal is to get which checkbox in the QTreeWidget is checked. But this I can do if you guys help me out with that one. Well, I cannot find a method that gives me the QList again so I could go all…
Patrick Bassut
  • 3,310
  • 5
  • 31
  • 54
10
votes
3 answers

How do I delete a top level QTreeWidgetItem from a QTreeWidget?

I'm attempting to remove a top level tree widget item if there are no child nodes within the top level item. What is the correct way to do this? I can't seem to find the API call within Qt's documentation. Is it safe to just call delete on the top…
Cameron Tinker
  • 9,634
  • 10
  • 46
  • 85
10
votes
1 answer

QTreeWidget reordering child items by dragging

I have a QTreeWidget which displays a single root node and one level of child nodes only. I need to permit the re-ordering of the child nodes. They must never be re-parented. This is how I enable the dragging of items in the QTreeWidget…
Simon
  • 2,208
  • 4
  • 32
  • 47
8
votes
3 answers

Why is there a 1 at the top of a QTreeWidget?

There is a 1 at the top of a QtreeWidget. How do i fix it?
Geore Shg
  • 1,299
  • 5
  • 23
  • 38
8
votes
4 answers

Is it possible to sort numbers in a QTreeWidget column?

I have a QTreeWidget with a column filled with some numbers, how can I sort them? If I use setSortingEnabled(true); I can sort correctly only strings, so my column is sorted: 1 10 100 2 20 200 but this is not the thing I…
JuanDeLosMuertos
  • 4,532
  • 15
  • 55
  • 87
1
2 3
35 36