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

python - Synchronizing two QTreeWidgets

I have two QTreeWidget's in a form, one without children, the other with children as depicted in the screenshot below. I want that the right tree be expanded if it is collapsed (and collapsed if it is expanded), each time an item in the left tree is…
maurobio
  • 1,480
  • 4
  • 27
  • 38
1
vote
1 answer

Drag and drop file into QTreeWidget inside of QDialog

I've been searching online for days and I cant find anything to help out with my specific problem. I'm trying to set up this dialog to accept files to be dropped into the QTreeWidget, named filesTreeWidget, but everything I've been searching online…
QConscious
  • 87
  • 1
  • 1
  • 11
1
vote
1 answer

In PyQt5, How to add a QSpinBox inside a QTreeWidget cell?

I'm trying to add a QSpinBox inside some cells of the QTreeWidget tree_parameters. l1 = QTreeWidgetItem(["String A", "", ""]) l2 = QTreeWidgetItem(["String AA", "", ""]) for i in range(3): l1_child = QTreeWidgetItem(["Child A" + str(i), "Child…
OriolBur
  • 11
  • 6
1
vote
2 answers

Dynamic size of QTreeWidget in PyQt5

I got a QTreewidget, which i want to be as small as possible, with probably only one branch. But i want the size to change accordingly to how that expands or collapses. As well as start out with a size that fits the filled part of the widget. I make…
Thomasedv
  • 382
  • 4
  • 22
1
vote
1 answer

How can I uncheck an item when pushing a button in PYQT5 treewidget?

I build tree structure using tree widget and all items are checked by default. There's a list saving some items which should be unchecked. What I want to do is to uncheck those items when clicking the push button. I can use findItems(uncheckitems,…
Zhentao
  • 140
  • 1
  • 10
1
vote
1 answer

How to centralize the QTreeWidget header

How to centralize the QTreeWidget header? I have the following QTreeWidget: And I want to centralize the header to look like this: I already tried to set this stylesheet: QHeaderView::section { text-align: center; } But it didn't work. I…
KelvinS
  • 2,870
  • 8
  • 34
  • 67
1
vote
1 answer

Get drag and drop source and destination in qtreewidget

I have simple tree in QTreeWidget (I use pyqt, but I think it`s not important). When I move item in this tree I want to change database, so I want to get this item object, parent of this item before moving and parent of this item after moving. But i…
mr_tron
  • 818
  • 8
  • 21
1
vote
2 answers

PyQt4 QTreeWidget parent and child indexes

I created PyQt4 QTreeWidget and added following QTreeWidgetItem structure. treeWidget = QTreeWidget() twi = QTreeWidgetItem(['Level_1']) twi.addChild( QTreeWidgetItem( ['SubLevel_1_1'] ) ) twi.addChild( QTreeWidgetItem( ['SubLevel_1_2'] )…
Damian
  • 85
  • 1
  • 2
  • 4
1
vote
2 answers

Set StyleSheet with Font size for elements in QTreeWidget

I try to set new font size for header and content of a tree widget. Problem here is: I can not set font size directly for the content because at the moment I set, the content does not appear yet. So I can just set StyleSheet, so when content…
songvan
  • 369
  • 5
  • 21
1
vote
0 answers

Qt4 QTreeWidget with VS2015 x64 win10

I've compiled qt 4.8.6 manually using vs2015 x64 native tools, since there no oficial support for this visual studio version. To avoid compilation errors and add new mkspec i was used this help (How to build Qt 4.8.6 with Visual Studio 2015 without…
1
vote
1 answer

List folders with Qtreewidget in Qt c++

I'm listing the folder using QTreeWidget. I wrote the following codes and it looks like the picture. But, I do not want it to be displayed like this. I want to add a box icon and add a dashed line to the left side of the box. I added a picture…
oğuzhan kaynar
  • 77
  • 1
  • 10
1
vote
2 answers

How to get names of files from a folder and add them to a tree widget as children in qt

I am making a program that needs to be able to output the names of files from a specific folder as items in a Tree Widget but I cannot seem to figure it out. I managed to do it in a list widget without too much hassle but I cant get that code to…
Nick
  • 31
  • 1
  • 5
1
vote
1 answer

How to select multiple items in treewidget and delete those items?

When I am selecting items in treewidget and then clicked on delete button then is is just deleting top most item only from treewidget Can you correct this code? This function is calling in connect statement while clicking on button void…
1
vote
1 answer

make QTreeWidget items expand on drag and drop

I'm trying to find a way, without re-implementing drag and drop, to have tree items expand when an item is dropped into them. I've looked into expand all on the top level addItem as well as over writing the dropEvent. The addItem approach doesn't…
James
  • 309
  • 1
  • 15
1
vote
1 answer

Show ForbiddenCursor only when mouse is OnItem in QTreeWidget

I am trying to display the Qt::ForbiddenCursor when I move a mouse over an item in a custom QTreeWidget but only when drop position is QAbstractItemView::OnItem. Here is the code void XProjectTreeWidget::dragMoveEvent(QDragMoveEvent * event) { …
Mihai
  • 389
  • 1
  • 4
  • 16