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

PyQt connecting signal from QComboBox inside the QTreeWidgetItem

I've made a QTreeWidget where I have comboBox as a QTreeWidgetItem. How do I hook up the signal correctly so that each comboxBox index changed will change the same row in the treeWidget ? Say if I change the action in row itemB from Add to Remove.…
moDong
  • 223
  • 2
  • 5
  • 9
1
vote
1 answer

How to highlight QTreeWidgetItem text

When the button is clicked I need the tree-item to turn highlighted (editing mode) (see the image below). Currently I have to double-click the item to set it in to highlighted mode. How to achieve this? from PyQt4 import QtCore, QtGui app =…
alphanumeric
  • 17,967
  • 64
  • 244
  • 392
1
vote
1 answer

How to edit QTreeWidgetItem when it is editable

When the item is double-clicked and the user enters a new item name I want this text value to be assigned to the item._name attribute which is printed onClick. How to achieve this? from PyQt4 import QtCore, QtGui app =…
alphanumeric
  • 17,967
  • 64
  • 244
  • 392
1
vote
1 answer

How to draw candlestick bar inside a column cell of PyQt4 QTreeWidget

I am trying to make a simple application with pyqt. What I want to make is a tree view with candlestick bar like the below, I decided to make it using this sample. But still, I couldn't find how to draw candlestick bar inside a cell of widget…
user1913171
  • 283
  • 4
  • 14
1
vote
1 answer

QTreeWidgetItem color

I am using the following stylesheet on a QTreeWidget to change the items style: QTreeWidget::item { padding-left:10px; padding-top: 1px; padding-bottom: 1px; border-left: 10px; } After that, I am trying to use the following code to…
hteso
  • 55
  • 2
  • 7
1
vote
0 answers

QTreewidget change row height to keep aspect ratio

I want to make a icon and text view with QTreeWidget. Icon would be column 0 and text would be column 1. And I hope to keep aspect ratio when I resize the column 0. At this moment, I can adjust each row heights to match the icon width using sizeHint…
Hyun-geun Kim
  • 919
  • 3
  • 22
  • 37
1
vote
1 answer

How do I get the selected and deselected items in a QTreeWidget?

I have a tree-widget to which I am adding items. Now I need to call a custom procedure when the item is selected or the item previously selected is unselected (Note: I am learning both Python and Qt - the later seem to by a little too much for…
MiniMe
  • 1,057
  • 4
  • 22
  • 47
1
vote
1 answer

QTreeWidget add same item twice

I'm trying to make some kind of recursion. If you open P then you can open P again or do something else. And here is my problem: I can't add same item twice. while (*it) { if ((*it)->text(0) == item->text(0)){ …
1
vote
1 answer

qtreewidget unwanted white space (additional unremovable rows)

I am creating a custom qtreewidget class that autoresizes its window to fit exactly the currently visible elements (I don't want to have to scroll). To do this, I run a count function to find the number of open qtreewidgetitems and their children…
Ethan Kay
  • 657
  • 6
  • 24
1
vote
1 answer

How to set QTreeWidgetItem as not Editable

After creating an item and setting it to as being editable: item=QtGui.QTreeWidgetItem() item.setFlags(item.flags() | QtCore.Qt.ItemIsEditable) I want to reset all item's flags and set this item back to non-editable. What would be correct syntax to…
alphanumeric
  • 17,967
  • 64
  • 244
  • 392
1
vote
1 answer

QTreeWidget that contains widgets and set row height issue

Setting row height is more or less trivial via inherit from QItemDelegate. The problem is that I can make the row size bigger but I cannot make it smaller if I add a widget inside. Any tip on this? Thank you in advance.
Frank Escobar
  • 368
  • 4
  • 20
1
vote
2 answers

Crash while calling setItemWidget

I am using a QTreeWidget and setting a widget for the QTreeWidgetItem in the QTreeWidget. It is working fine but when I do the same for second time, the application is crashing. The below is working fine. QTreeWidget* treewidget = new…
Sankar
  • 41
  • 1
  • 4
1
vote
1 answer

Is there a way to detect when all child items within a QTreeWidgetItem have been marked 'hidden'?

Is there a preferred way to detect when all of a QTreeWidgetItem's children are marked as hidden? Currently, I'm iterating over all of them every time any of them are hidden.
moswald
  • 11,491
  • 7
  • 52
  • 78
1
vote
1 answer

QTreeWidgetItemIterator with a "subtree"

I am trying to iterate over a part of a QTreeWidget. So I use a QTreeWidgetItemIterator and the constructor with a QTreeWidgetItem. But the iterator does not visit only the item and its children but "ascend" and continue after the given…
Maluna34
  • 245
  • 1
  • 16
1
vote
2 answers

How to capture resizing of QTreeWidget columns

I need a column in my QTreeWidget which's width is always x pixels. So i want to capture a resize of my QTreeWidget columns, to set the with back to my x on resize by user. But i can't find any Signal like columnWidthChanged. Is there any way to…
Haselnussstrauch
  • 333
  • 2
  • 10