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 validity check on QTreeWidgetItem

I'm building a QTreeWidget where I'm implementing adding new item and renaming functionality. I'd like to check the validity of the new name given by user, including: the name can only contain a list of valid characters. This is achieved already by…
Jason
  • 2,950
  • 2
  • 30
  • 50
1
vote
1 answer

setSectionResizeMode() crashes when the column at given index isn't created yet

I have a QTreeView object with two columns. I want the first one to be able to stretch, and the second one to have a fixed width. This question has an answer which I tried to apply to my case. I set these to my tree…
user3132457
  • 789
  • 2
  • 11
  • 29
1
vote
1 answer

Drag and drop with two QTreeWidget, filter QTreeWidgetItem's acording to their previous set data

Im my project I have two qTreeWidgets (let's say A and B), I want to drag Items from treeWidget A to treeWidget B. I have multiple problems: Not all of the items stored in A should be draggale. At other parts of my code I seperate them by defining…
Hoehli
  • 154
  • 10
1
vote
1 answer

QTreeWidgetItems and QLineEdit echomodes

To the point: How do I get a QTreeWidgetItem to respect a QLineEdits setEchoMode(QLineEdit.Password) ? I've been banging my head against the wall for this for the last day: I have a subclass of QTreeWidgetItem (which simply adds one extra field to…
Dnlhoust
  • 118
  • 1
  • 9
1
vote
1 answer

QTreeWidget with non-native scroll bar when background changed

I need a QTreeWidget with transparent background so it has the same color as the native light-gray window background. This works fine by setting the background to transparent. The problem is that if I do this, the scroll becomes non-native looking.…
Rolli
  • 41
  • 7
1
vote
1 answer

formatting child items in qtreewidget pyqt5

STYLESHEET = '''QTreeWidget {border:None} QTreeWidget::Item {height: 80px; border-bottom:2px solid black; color: rgba(255,255,255,255);} /* +++ */ QTreeView { …
Great Person
  • 62
  • 10
1
vote
1 answer

Save Qtreewidget item and restore it with selection

I need support to my little software with Qwidget and QTreeWidgets. see below figure. This is how my Qwidget looks like. I want to restore Qtreewidget items and widget when I close the window and restore it with previous selection. as Marked on…
Pavel.D
  • 561
  • 1
  • 15
  • 41
1
vote
0 answers

Disappearing data in extended QTreeWidgetItem

UPDATE: (SOLVED) Thanks to eyllanesc for making me write a working example code of my problem. That made me find the problem. Here is a working code with a fixed problem: from PyQt5.QtCore import * from PyQt5.QtWidgets import * from PyQt5.QtGui…
pawliux
  • 183
  • 2
  • 10
1
vote
1 answer

Make tree folder from QTreeView or QTreeWidget

read folder tree from a Rest API, then show them to user Example json response after call…
kien bui
  • 1,760
  • 2
  • 17
  • 33
1
vote
1 answer

Inserting a child Item into a row of QTreeWidgetItems

I have setup my QTreeWidget such that each cell is filled with comboboxes, however I would like to create a text edit widget next to the selected combobox (or overwrite the existing combobox), depending on which combobox item the user has…
Reginald Marr
  • 387
  • 2
  • 16
1
vote
1 answer

QTreeWidget icon

I'm developing an Qt application and I was displaying some data in QTreeWidget widget, but I needed it to adjust it to fit it's content so I changed the QTreeWidget to a custom widget from this post : How to make an expandable/collapsable section…
madasionka
  • 812
  • 2
  • 10
  • 29
1
vote
1 answer

Disable selection of parent rows in a QTreeWidget

I populate nested lists in a QTreeWidget, and I need to disable the selection of parent rows. The code is: def fillTree(self): ''' Fill UI with list of parts ''' roots = ['APLE', 'ORANGE', 'MANGO'] childs = ['body', 'seed',…
kiryha
  • 183
  • 1
  • 2
  • 14
1
vote
1 answer

Scrolling a QTreeWidget with gestures

I am writing a program in Python 3.5 and PyQt5. I have a QTreeWidget that has a list of items in it. I want to hide the scrollbar and make touch scrolling for it in the vertical direction. This is my code: self.category_tree =…
Nimda
  • 103
  • 2
  • 13
1
vote
1 answer

How to delete QTreeWidgetItem's children

The code creates a single dialog with QTreeWidget and a button. When the button is clicked I want to delete all the children of the Root item that is currently selected. How to achieve it? app = QApplication([]) class Dialog(QDialog): …
alphanumeric
  • 17,967
  • 64
  • 244
  • 392
1
vote
0 answers

How to make QTreeWidgetItem expandable

Code below creates a single QTreeWidget. I want each "Root" item to display the "expand" arrow next to its name but I don't want to create the Root's children items yet (I would rather create the children items after the user clicks the "Expand"…
alphanumeric
  • 17,967
  • 64
  • 244
  • 392