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
2
votes
4 answers

How to GET row height in QTreeWidget/QTreeView

I just want to get the row height from a QTreeWidgetItem. I searched a lot but nothing hits. What I want to do is to resize the wrap widget which contains a QTreeWidget to enable all rows in the tree are visible (or to say, it will be a bottomless…
K--
  • 659
  • 1
  • 7
  • 18
2
votes
1 answer

Change sections name in QHeaderView

I use a QTreeWidget to display multicolumn items, and I want to have a header with column names. However, I only get numbers, as shown in this screenshot: Here is a piece of my code, which should do it (but does not): class…
Valentin Lorentz
  • 9,556
  • 6
  • 47
  • 69
1
vote
1 answer

Qt QTreeWidget Context Menu: Add items under another o delete items.

I managed to create a context menu that gets activated after a right click on each item of a QTreeWidget tree: contextMenu = new QMenu(ui->treeWidget); ui->treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu); addElement = new QAction("Add…
Fracu
  • 835
  • 1
  • 13
  • 28
1
vote
1 answer

Error subclassing QTreeWidget

I am getting a mysterious error trying to subclass QTreeWidget. Below is code from the relevant files. In QtDesigner, I have promoted a QTreeWidget to a treeWidget, but I get the following error: Error 1 error C2061: syntax error : identifier…
George
  • 343
  • 2
  • 15
1
vote
1 answer

QTreeWidgetItem: How can I get the selected item?

I am currently a student programmer using Qt to build a GUI inteface at work and I am currently running into a problem finding a solution in the Qt Documentation On the QTreeWidgetItem. I currently have an interface that has buttons to edit, delete,…
Wylie Coyote SG.
  • 1,009
  • 6
  • 22
  • 37
1
vote
2 answers

PyQt - load XML into QTreeWidget

I'm trying to make a basic XML story maker in PyQt. So far I've been able to figure out everything my self, but I've run into a bit of a snag. I can't figure out how to load an XML file into a QTreeWidget. I need to preserve the hierarchy, but said…
bojjenclon
  • 29
  • 1
  • 1
  • 4
1
vote
1 answer

QTreeWidget selected click edition and double click

I have a QTreeWidget for which I want double click to open a specific thing and single click to start renaming of the item, but I don’t want both actions to happen when I double click. Right now when I double click my tree item I get my things to…
1
vote
1 answer

HowTo draw QTreeWidgetItem with different style?

Here is the main problem: I'm using QTreeWidget class as a main tree, which must show me this tree structure: [Today] [Row1] [Row2] [SubRow21] [SubRow22] [Row3] [Yesterday] [Row4] [SubRow41] [etc] With Qt Designer I…
mosg
  • 12,041
  • 12
  • 65
  • 87
1
vote
2 answers

Drag and Drop between QTreeWidgets

Is it possible two drag and drop items between two QTreeWidgets? I have one tree-widget Tree1 and a second one Tree2. Tree1 is somehow the master which contains all elements (only top-level elements, child elements are disabled). Only sorting should…
EGuy
  • 211
  • 1
  • 3
  • 10
1
vote
1 answer

PySide2 - Qt - Disable drag selection when using ExtendedSelection on QListWidget / QTreeWidget / QTableWidget

I am trying to find a solution to use the ExtendedSelection (single selection and multiple selection by using ctrl and shift keys), but I want to prevent using the multiple selection by dragging the mouse up&down after a mouse click. Working…
laurapons
  • 971
  • 13
  • 32
1
vote
0 answers

What is the easiest way to set data of a QTreeWidget from a numpy array?

Tried: def setTreeValues(self, data: [numpy.array]) -> None: """ ARGS: ID signals sum_errors max_error number_errors status (int) (str) (float) (float) (int) …
1
vote
1 answer

Drag and Drop TreeWidget

I'm trying to make a treewidget that can change children between parents with the drag and drop method, but a children can never be turned in a parent. Right now this is my class: class Tree(QTreeWidget): def __init__(self, parent=QWidget): …
Shadow
  • 65
  • 8
1
vote
1 answer

How to get an Item's index in QTreeWidget?

I have a QTreeWidget in my project for which I want to get the index of its items. My QTreeWidget is a list of tests that I want to perform. For example, Test 1, Test 2, Test 3, Test 4 etc. Test 2 and Test 4 have children Test a, Test b, Test c etc.…
coder
  • 21
  • 3
1
vote
1 answer

QTreeWidget clear empty space at the bottom of widget

Is this example i have a QTreeWidget with 4 columns. The last column is filled by QFrames. File ui.py from PyQt5 import QtCore, QtGui, QtWidgets import sys if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) …
Chris P
  • 2,059
  • 4
  • 34
  • 68
1
vote
0 answers

Qt QTreeWidget looping over top level items slows down after sorting

I've got a Qt related question (for c++) regarding the QTreeWidget and hope someone can help. I am working with the QTreeWidget and have run into a performance issue that I can't seem to solve. I basically have made a simple extension of it that…
Fiurilli
  • 11
  • 2