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

Remove space from QLabel in a QTreeWidget

I've added QLabel widgets to my QTreeWidget to work around the word wrapping issue in QTreeWidget. (see how to word wrap a QTreeWidgetItem). The QLabel widgets appear to have spacing around the text which for some reason disappears when the text…
Jason
  • 1,098
  • 12
  • 33
3
votes
2 answers

Using QTreeWidgetItemIterator in PyQT4 to return isChecked from QTreeWidget as a dictionary (or...something)

Check the edit for final code! So...I'll admit that I'm drawing an absolute blank here due to lack of knowledget and will just present my code and pray a little bit. Using this fantastic xml to QTreeWidget generator that ekhumoro coded I've added in…
Amdingo
  • 100
  • 1
  • 8
3
votes
2 answers

Displaying a tooltip for QTreeWidgetItem when it's hovered without calling setTooltip() for every item

I want to display a tooltip for QTreeWidgetItem that's hovered. However, getting a tooltip is not a very fast process in my case, so I don't want to call setTooltip() for every single item. I want to do it on demand, on some event or signal. What's…
Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335
3
votes
2 answers

Is it possible to set multiple items selected in QTreeWidget?

setCurrentItem only sets one item selected. I don't see any method to set more than 1 item selected programmatically, but maybe I'm overlooking something? Of course, my tree widget is configured to enable multiple selection. Note that I'm using…
Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335
3
votes
3 answers

Can you set a QWidget to take up an entire column of a QTreeWidget?

I have a custom QTreeWidget subclass that I'm using to display track names/etc. in my MIDI editor project (https://github.com/waddlesplash/ragingmidi). I'd like to add another column to this tree widget, but with one widget taking up the whole…
waddlesplash
  • 743
  • 1
  • 6
  • 25
3
votes
1 answer

Where are my QTreeWidgetIcons?

I have a QTreeWidget with QTreeWidgetItem items, however only the root node is showing its icon: I've been scratching my head on what could turn it off, any hints? ui->folderTree1->setUpdatesEnabled( false ); QTreeWidgetItem* treeRoot1 = new…
Phil Hannent
  • 12,047
  • 17
  • 71
  • 118
3
votes
1 answer

QTreeWdiget adding child element at specific location

I am trying to build a tree in a way that I can insert the element where I want. This is my tree in its initial stage: +Project +--Version 1.0 +--Version 2.0 Now, let's suppose I made a Version 1.1 and I would like to add it at the location…
Ferenc Deak
  • 34,348
  • 17
  • 99
  • 167
3
votes
2 answers

How to Add a Button or other widget in QTreeWidget Header?

Can anyone give me a hint on how to place a button in the header of QTreeWidget A minimal example is more than welcome?
Nick
  • 31
  • 1
  • 4
2
votes
1 answer

QTreeWidget Passing multiple Items (more then one selection) through a function

I am a student programmer using Qt to build a GUI for work. I have ran into an issue; more or less and inconvience of sorts wiith multiple selections in the QTreeWidget. My GUI has a main interface with a QTreeWidget as the central item in this…
Wylie Coyote SG.
  • 1,009
  • 6
  • 22
  • 37
2
votes
2 answers

QTreeWidget and PyQt: Methods to save and read data back in from file

I'm working on a project that contains a QTreeWidget. This widget will have Parent nodes with childs nodes and or other siblings nodes. Attached to each node will be a unique ID in the form of an integer as well as a name. Now..... what methods…
thedax
  • 131
  • 1
  • 5
2
votes
2 answers

Disabled checkbox for QTreeWidget

Does anyone know how to make an uneditable checkbox ina QTreeWidgetItem but keep the QTreeWidgetItem selectable?
Jay
  • 3,373
  • 6
  • 38
  • 55
2
votes
2 answers

Automatically sorting on insert in QTreeWidget

I have a QTreeWidget that I insert items in, and the user can select a column to sort it. As the items are being inserted, they just get appended to the end instead of having the sort being done automatically. If I click the header to switch between…
staackuser2
  • 12,172
  • 4
  • 42
  • 40
2
votes
1 answer

Reordering items in a QTreeWidget with Drag and Drop in PyQt

I have a QTreeWidget with what I thought all the proper settings setup in order to be able to reorder items by dragging them around. It can work, at times, but more often than not I drag an item into another one and it either disappears or becomes a…
Cryptite
  • 1,426
  • 2
  • 28
  • 50
2
votes
1 answer

How to resize a QTreeWidgetItem when their widget is changed?

I have made a custom QTreeWidget class to make a kind of collapsible list of widgets. Now when I change the widget in one of the section, let's say from a short widget to a taller one, the size does not update to respect the taller widget's…
Sepand.S
  • 25
  • 1
  • 5
2
votes
2 answers

Synchronized Qt TreeWidgets

I'm new to Python and PyQt. What is the best way to keep 4 QtTreeWidgets synchronized so that the items are the same as well as all the attributes of all the items? These widgets appear in different dialog boxes at different times during a session.…
iwonder
  • 97
  • 2
  • 5