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

How to select or highlight all items in a QTreeWidget?

I'm trying to build a context menu that user can right-click on a QTreeWidget and select all items.
moDong
  • 223
  • 2
  • 5
  • 9
2
votes
1 answer

Get the position of a drop relative to an item on a QTreeWidget

I have a custom QTreeWidget class with the dropEvent() method overridden. Here is the method: void QCustomTreeWidget::dropEvent(QDropEvent * event) { QModelIndex droppedIndex = indexAt(event->pos()); if (!droppedIndex.isValid()) …
Mihai
  • 389
  • 1
  • 4
  • 16
2
votes
2 answers

How to make QTreeWIdgetItems editable selectively

All the cells are currently editable (editable on double-click). I only need the column 0 to be editable and all others not. How to achieve this? from PyQt4 import QtCore, QtGui app = QtGui.QApplication([]) class Tree(QtGui.QTreeWidget): def…
alphanumeric
  • 17,967
  • 64
  • 244
  • 392
2
votes
1 answer

Qt treewidget python; iterate columns

Given a tree widget in PyQt4 with some rows and columns: 1) Is there a way to easily iterate over all cells? 2) How can one check if a checkbox is checked apart from the first column? So far I only managed to get the results of the checkboxes in the…
Kam Sen
  • 1,098
  • 1
  • 11
  • 14
2
votes
2 answers

QTreeWidget - width of column with widget

I have QTreeWidget with two columns. The first column is the text, and the second is QPushButton. I can not specify the size of buttons and the size of the second column. When you try to set the size of the column of content, the second column…
Vika
  • 153
  • 3
  • 4
  • 12
2
votes
1 answer

Add QSpinBox to a child of QTreeWidgetItem

I know how to add a QSpinBox to a QTreeWidgetItem : _spin_speed = new QSpinBox(); ui->treeWidget->setItemWidget(ui->treeWidget->topLevelItem(0) , 1 , _spin_sizePicture); But how to add a QSpinBox to a child of QTreeWidgetItem? By "child" I mean…
Pascal Goldbach
  • 977
  • 1
  • 15
  • 34
2
votes
1 answer

Delete currently selected item from QTreeWidget

Im working with a Qt GUI application, and i have a QTreeWidget with values. I have added each value to the tree like so: QTreeWidgetItem *node = new QTreeWidgetItem(); node->setText(0, m_stringList[i]; node->setFlags(Qt::ItemIsSelectable |…
Cody Pritchard
  • 635
  • 1
  • 9
  • 28
2
votes
1 answer

Iteration of a QTreeWidget

I have a QTreeWidget that I am using to represent a breakdown structure of data. Basically I plan on using my QTreeWidget in a way to track the population of certain demographics in cities. For example: Males …
sudobangbang
  • 1,406
  • 10
  • 32
  • 55
2
votes
1 answer

Comparing QTreeView/QAbstractItemModel to QTreeWidget

I'm building a tool in PySide for Maya (3D software) that auto versions and saves files in a directory. I've spent the past few days trying to convert my initial QTreeWidget code into a model/view pattern with QTreeView and QAbstractItemModel to get…
2
votes
0 answers

How to change highlight color on QTreewidgetItem

I have wrote an app using QTreeWidget. Currently when selecting an item using the mouse, this item is highlighted in blue as probably default palette. How can I change the property to modify the highlight color when a QTreeWidgetItem is selected…
Seb
  • 2,929
  • 4
  • 30
  • 73
2
votes
1 answer

QTreeWidget insert between two items using drag and drop

I have a QTreeWidget which I have setup like so... ModelTreeWidget::ModelTreeWidget(QWidget *parent):QTreeWidget(parent), mpModelStruct(nullptr), mpModeldragging(nullptr), mpBufferModel(nullptr), mpModelCurrent(nullptr) { …
foboi1122
  • 1,727
  • 4
  • 19
  • 36
2
votes
2 answers

pyqt QTreeWidget signal on item drop

I need to enable a button in my app whenever something is dropped to my custom QTreeWidget. I sub-classed QTreeWidget to implement drag and drop of custom data. But I'm not able to find a way to get notified when something is dropped into my custom…
NGambit
  • 1,141
  • 13
  • 27
2
votes
1 answer

Can a QListWidget have groupings?

I currently have a QListWidget that displays many items that are user selectable (and dragable). In my application, when an item is checked it will be reordered above the unchecked items. The user can also drag/drop to adjust the order of the…
NewGuy
  • 3,273
  • 7
  • 43
  • 61
2
votes
1 answer

QTreeWidgetItem Change - Detect Enter/ESC

I'm developing a Qt/C++ app with a QTreeWidgetItem. When a new item is created I set it setEditable and it allow me to fill directly in the UI the new name. I'm currently using itemChanged as shown below to catch the change and save it. By default,…
Seb
  • 2,929
  • 4
  • 30
  • 73
2
votes
1 answer

QTreeWidgetItem::insertChild does not its work

I have a QTreeWidget and I would like to insert a child at a certain index. I tried with void QTreeWidgetItem::insertChild ( int index, QTreeWidgetItem * child ) but any index I put, it inserts the child at the end of all children the parent has.
user3473325
  • 103
  • 1
  • 8