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
0 answers

Clearing and displaying all items with single click in QTreeWidget PyQT

I'm struggling with finding a solution to clear() all QTreeWidget items. I don't want to remove each item separately but want to do it in a single shot as I might have tens of thousands of items to clear. So I have a function clear_tree which…
Zwornik
  • 31
  • 5
1
vote
1 answer

PyQt5: Drag and drop between item peers in a QTreeWidget

Nodes of the same level can be dragged and prevented from entering each other, not other parent nodes. I overwrote the dragMoveEvent and dropEvent methods in the QTreeWidget.I only have the second layer effect correct, which can drag each other…
1
vote
1 answer

Add custom widget to a QTreeWidget column in PyQt5

I want to have a QTreeWidget with hierarchical items where one column contains a custom widget. I created a custom widget that contains a QLabel and a QSpinBox in a horizontal layout. MySlider.py looks like this: from PyQt5 import QtWidgets from…
Farzad
  • 131
  • 1
  • 2
  • 10
1
vote
1 answer

How to keep QWidgets in QTreeWidget hidden during resize?

I have a simple UI with QWidgets within a QTreeWidget. Some of them need to be hidden. Every time the application is resized, all QWidgets become visible. Below is a minimal example to demonstrate the issue. How can I make sure the QWidgets stay…
dukeeloo
  • 161
  • 7
1
vote
1 answer

Extra row appearing in QTreeWidget PyQt

I've a piece of code in which I've added two sub-items to a QTreeWidget parent item. The sub-items are set to be "editable". I'm facing two problems here: There appears an extra row with empty editable items. (I want "Min" and "Max" in the same…
Goku
  • 23
  • 7
1
vote
1 answer

Prevent recursion when changing QTreeWidgetItem flags

I'm trying to make a very basic password manager and I've encountered an issue when trying to edit an item. When the button "Edit Password" is pressed, it makes the currently selected item editable, and I would like it to be removed once the user is…
1
vote
1 answer

Drag and Drop QTreeWidgetItem to QGraphicsView with custom data

I've a class containing a QTreeWidget, where I have some QTreeWidgetItem. I want to drag and drop a QTreeWidgetItem into a QGraphicsScene, in order to create an object in there. The object is a rectangle with the text of the QTreeWidgetItem in…
Jepessen
  • 11,744
  • 14
  • 82
  • 149
1
vote
0 answers

How to add horizontal scrollbar to only one column in QTreeView

I've did some digging but didn't found an answer anywhere. How could I add horizontal scrollbar for only one column out of 3 existing in QTreeView?
tisseq
  • 33
  • 2
1
vote
1 answer

Moving items from QTreeWidget to QListWidget

Im trying to move the items that is checked to the empty list when the user press the ''Ok'' button. But i get this error: Traceback (most recent call last): File "Desktop/abstract.py", line 42, in okButtonSlot self.listWidget.addItem(item)…
nabs
  • 35
  • 6
1
vote
1 answer

How to make QTreeWidget call sizeHint when resized?

I am using a custom QStyledItemDelegate in order to display data in a QTreeWidget. Thus I have implemented the paint() and the sizeHint() functions. The painting works fine, but I have some issues with the sizeHint. The problem is that I am…
Raven
  • 2,951
  • 2
  • 26
  • 42
1
vote
1 answer

How to customize Qtreewidget item editor in PyQt5?

I am making a QtreeWidget with item editable,but the problem is with the Item Editor or QAbstractItemDelegate(might be called like this,not sure).I am unable to change the stylesheet,actually i dont know how to do this.And also i want the selected…
Hacker6914
  • 247
  • 1
  • 9
1
vote
1 answer

How to set small column widths in QTreeWidget?

I have a QTreeWidget with two columns and I'm trying to set the second column width to a very small value. If I set the width to over 35 it will resize correctly. However if I try to set the width below 35 it will always end up at 35. Interesting…
1
vote
1 answer

How to get QTreeWidget item's text, when a checkbox within is toggled?

I've made a QTreeWidget that has a number of rows, each row with a text item, and a checkbox. How do I get the text, when the checkbox is toggled? I know that I can use currentItem() to get the currently selected TreeWidgetItem, but the row isn't…
Jesse
  • 143
  • 1
  • 1
  • 10
1
vote
1 answer

How to have QTreeWidgetItems of different heights in a QTreeWidget utilizing QStyledItemDelegate?

NOTE: it turned out that the problem was not due to the implementation of QStyledItemDelegate, but it was the fact that in the constructor of MyTreeWidget I was calling setUniformRowHeights(true). The code below and the solution posted by…
santahopar
  • 2,933
  • 2
  • 29
  • 50
1
vote
1 answer

QTreeWidgetItem.insertChild at index 0

I am trying to insert a new child item at the top of the group of items. The index value does not seem to be honored and the item goes to the end of the list. I searched and did not find many hits for this type of operation in QTreeWidgets. I did…
EdLipson
  • 89
  • 2
  • 9