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
1 answer

QTreeWidgetItem setting not selectable clears the selection

I have a QTreeWidget and I want certain rows to be non select-able, which can be achieved by QTreeWidgetItem::setFlags(treeWidgetItem->flags() & ~Qt::ItemIsSelectable). The problem is that I have an existing row that is already selected and later I…
santahopar
  • 2,933
  • 2
  • 29
  • 50
2
votes
1 answer

Pyqt5 QTreeWidget CurrentItemChanged signal sending integers as previous item

I've got a QTreeWidget item and the signal CurrentItemChanged connected to a method that updates the GUI based on a DB lookup. The CurrentItemChanged documentation says it will pass QTreeWidgetItems as arguments to the method. First the current…
bythenumbers
  • 155
  • 1
  • 3
  • 10
2
votes
1 answer

QTreeWidgetItem.addChild() doesn't work in some cases?

I'm having trouble with adding a child to a top-level item in a QTreeWidget. I have a QTreeWidget in which the user can click a button to add items called "steps". It contains only two levels and is presented as in the following example: -…
Gnahahaaa
  • 23
  • 7
2
votes
1 answer

PyQt [QTreeWidget]: How to add Radiobutton for items?

To this question I am referring to the answer from @Andy PyQt Tree Widget, adding check boxes for dynamic removal There @Andy shows how to add CheckBox into the QTreeWidget, which works perfect. I would like ask here, how to add RadioButton into…
Rt Rtt
  • 595
  • 2
  • 13
  • 33
2
votes
1 answer

How to populate QTreeWidget from tuple?

I'm pretty new to Python so please bear with me. I'm trying to populate a QTreeWidget from a tuple, but I can't seem to get it too work. TreeList = ({ 'Header1': (( 'Item1', 'Item2', )), 'Header2': (( 'Item1', …
artomason
  • 3,625
  • 5
  • 20
  • 43
2
votes
2 answers

Change text color of a specific column for QTreeView

I have widget that inherits from QTreeView, and I want to change the text color, but only for a specific column. Currently I set the stylesheet, so the entire row changes the text color to red when the item is selected. QTreeView::item:selected…
laurapons
  • 971
  • 13
  • 32
2
votes
2 answers

one type of file format in QTreeView

Is it possible to set only one file format visible to the user? I'm searching it in documentation, but I can't find it... If not, which other widget you are suggesting to use?
lvp
  • 2,078
  • 18
  • 24
2
votes
1 answer

How to connect QTreeWidget and QStackedWidget in PyQt4?

I'm sorry but just a beginner of Python. I just want to change index of QStackedWidget by the item click of QTreeWidget. I searched for the tutorials of SIGNAL and SLOT online, but just cannot solve the problem. The parameters in QTreeWidget signal…
Mersper
  • 107
  • 8
2
votes
1 answer

How to set open/close icons in QTreewidget

How do I manage icon events for open and close in a QTreeWidget? I have this code: iconNameOpen="folder" iconNameClose="folder_orange_open" if ID>0:#file iconNameFile="file_important" …
user3589887
  • 139
  • 2
  • 13
2
votes
1 answer

Python PYQT QTreeWidgetItem selected cell

I have QTreeWidget like this What should i do to get value from selected row and filename column ? I have current selected item item = self.ui.files_treewidget.currentItem() but how to access to specific cell?
RogerZ
  • 61
  • 1
  • 2
  • 3
2
votes
1 answer

Directory tree in a QTreeWidget

I'm using zipfile and tarfile Python modules to open, extract and compress archives. I need to display the archive structure in a QTreeWidget, and I don't know how to go on. To get the infos I use the function infos(path) from this file. I would…
rubik
  • 8,814
  • 9
  • 58
  • 88
2
votes
1 answer

PyQt: How to expand all children in a QTreeWidget

There is no real problem, I have just a cosmetic problem. Well, first I create a form with Qt Designer. On this form I place a QTreeWidget. We are still in Qt Designer. In QTreeWidget, I make a few entries (parents), and then I also take a few child…
Sophus
  • 379
  • 6
  • 21
2
votes
2 answers

Can QTreeWidget jump to a specific line(specified by QTreeWidgetItem or column)?

I use setCurrentItem() to focus on a specific item,but the QTreeWidget does not jump to the specific item correspondingly. Are there any function of QTreeWidget can do this?
phuinews
  • 67
  • 1
  • 4
2
votes
1 answer

Problem with QVariant/QTreeWidgetItem/iterator on qt4.4.3

In my qt app I have this object, filled before setting up my QTreeWidget's content: QList items; I fill the QList by this way: QVariant qv; // I need this for "attaching" to the item my linuxPackage…
JuanDeLosMuertos
  • 4,532
  • 15
  • 55
  • 87
2
votes
1 answer

PyQt: Adding children to TreeWidget dynamically

I have a TreeWidget with one or more parents, each of which has a variable number of children. The tree is initially populated (say, with data from a database in a real application). I would like that a user could be able to add one or more children…
maurobio
  • 1,480
  • 4
  • 27
  • 38