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 change QTreewidget header background when hover

i am making a program with QTreeWidget and i dont know how to change its header background color when hover i tried but hover is not working.This is my code. self.mytreeview.setStyleSheet(''' QHeaderView::section { background-color:…
Hacker6914
  • 247
  • 1
  • 9
1
vote
1 answer

How to programmatically stop editing QTreeWidget in Qt?

I have a QTreeWidget and two buttons "+" and "-". When I press "+" I want to add new item to QTreeWidget and I want that item to be in edit mode. I managed to do that with following code (it gets called every time "+" is pressed): //…
dosvarog
  • 694
  • 1
  • 6
  • 20
1
vote
1 answer

Increase the size of qtreewidget

It turned out to be a problem for me to make a signal for Qtreewidget in PyQT5. You need to increase the size of QTreeWidget when you click "increase" and decrease it when you click again (like a filter in Excel) like this Code: …
Linearlys
  • 13
  • 3
1
vote
2 answers

How do I retrieve the mimeData for a particular item in a QTreeWidget?

I am trying to programmatically "drop" an item onto a QTableWidget using QTableWidget::dropMimeData(). I know which item I want to drop and I know that QTreeWidget has a QTreeWidget::mimeData() function, but I can not use that mimeData() function…
Matthew
  • 13
  • 3
1
vote
1 answer

Drag item from QTreeWidget to QGraphicsView

I've the following situation: Basically I've a QTreeWidget with some items, and a canvas that's a subclass of a QGraphicsView. What I want to accomplish is to drag a QTreeWidgetItem in the QGraphicsView subclass. When the mouse is released in the…
Jepessen
  • 11,744
  • 14
  • 82
  • 149
1
vote
1 answer

Debug assertion (invalid comparator) when sorting in a QTreeWidget

I've the following custom QTreeWidgetItem that I use in my QTreeWidget: #ifndef FEDERATELISTITEM_HPP_ #define FEDERATELISTITEM_HPP_ #include class FederateListItem : public QTreeWidgetItem { public: enum Type : int { …
Jepessen
  • 11,744
  • 14
  • 82
  • 149
1
vote
1 answer

PyQt5 QTreeWidget in layout showing an extra column outside the widget

I am trying to write a PyQt5 widget which will be a basic preset manager inside an application. I am trying to use the QTreeWidget to display the structure of each type. I have this weird issue, where I see an extra QTreeWidget with a column named…
vaco
  • 21
  • 3
1
vote
1 answer

Use a QTextCursor in a QTreeWidget in PyQt5

I would like to underline something in a QTreeWidget with a red wave like this : I tried to pull this off with a QTextCursor but apparently it's not possible. Anyone knows another way ? As an exemple, here is a way to underline a word with…
DigitalRomance
  • 305
  • 2
  • 7
1
vote
0 answers

Reorder items in a tree

I want to be able to reorder the items in my_tree and I have somewhat achieved this as…
Giuseppe
  • 143
  • 1
  • 10
1
vote
0 answers

QTreeWidget with multiple columns limits number of child items

Could anyone help me understand the following behaviour? If I run this PyQt script I can generate a simple window with a QTreeView with multiple child items: import sys from PyQt4.QtGui import QApplication, QWidget, QTreeWidget, QTreeWidgetItem,…
Phil Boltt
  • 786
  • 6
  • 14
1
vote
1 answer

PyQT5 QTreeWidget get full path of clicked element

I hope you all safe and healthy. My problem is simply I am trying to make a video player and I have QTreeWidget with elements (folders & files) from given path on it. I want to make play video when double clicked on element in QTreeWidget. # How I…
1
vote
1 answer

How add multiple comboboxes as a child to a QTreeWidgetItem

I'm in a situation where I need to dynamically generate a UI based on a randomly differing amount of parents with a random amount of nested children. When the child QTreeWidgetItem is expanded, it's child item should look like this: -Parent …
1
vote
1 answer

Determine visible size of a QTreeWidget column

I need to determine the VISIBLE width of a column within a QTreeWidget. I'll explain my problem with a small example. A QTreeWidget defines three columns with the fixed width of col 1=200 px, col 2=100 px and col 3=300 px. The widget itself has a (…
1
vote
1 answer

Add and remove checkboxes for QTreeWidgetItems

My app is written with PyQt5. I have a QTreeWidget with some elements: Parent --Child 1 --Child 2 I want to add and remove checkboxes to child elements dynamically. I managed to add the checkboxes with item.setFlags(item.flags() | 16) and…
El_Presidente
  • 63
  • 1
  • 5
1
vote
1 answer

How to back reference Qt5 Tree to a set of data?

I’m trying to use either TreeView or the TreeWidget to create a hierarchy that displays just a icon/string to represent a path. I’d like a signal/slot so that double-clicking on an item opens a new window to edit the contents of that path. Currently…