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
8
votes
5 answers

QTreeWidget to Mirror python Dictionary

Is there a way to make a QTreeWidget mirror the changes made to an internal data structure such as dictionary? It seems like they would have created this functionality within the api, because there are many programs which may interact with…
chase
  • 3,592
  • 8
  • 37
  • 58
8
votes
2 answers

pyside qtreewidget constrain drag and drop

I'm trying to add a constraint to the QTreeWidget drag and drop function to prevent the branches from entering another branch in another root. Here's an example to make things more clear: I have 4 objects. Lets call them apple, banana, carrot,…
ScottWilson
  • 360
  • 3
  • 15
8
votes
1 answer

Have multi-column QTreeWidget root items

I am using a QTreeWidget to display items in categories. Items will use several columns, but I want categories (ie. root items) to use the full width of the widget. How can I do that? And a piece of my code: class BugsList(QtGui.QDialog): def…
Valentin Lorentz
  • 9,556
  • 6
  • 47
  • 69
7
votes
1 answer

PyQT QTreeWidget iterating

I have two columns in a QTreeWidget, one column represents a list of urls and the second represents results. I have loaded the list of urls in first column and now I want to iterate this list and during the iteration, change the text in the second…
Nuncjo
  • 1,290
  • 3
  • 15
  • 16
7
votes
1 answer

Python PyQt5 QTreeWidget sub item

How to create sub item in the QTreeWidget? I was able to create top level items (listing below), but still looking for sub items. PyQt->5.6 Python->3.5 Spyder->3.0.2 import sys from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QApplication,…
Damian
  • 85
  • 1
  • 2
  • 4
7
votes
3 answers

PyQt - get list of all checked in QTreeWidget

I am building a simple application to open up a folder of data and plot that data. Importing the data updates a QTreeWidget that shows which signals are available to plot. Ex: The QTreeWidget is populated after the data is imported using: def…
dan_g
  • 2,712
  • 5
  • 25
  • 44
7
votes
3 answers

Set column width for QTreeWidget

Is there any way to set column width for QTreeWidget from code? I want to chage default width of first column. I'm using PySide.
xander27
  • 3,014
  • 8
  • 30
  • 42
6
votes
1 answer

PyQt QTreeWidget.clear() causes crash

I've got python 2.5 and PyQt 4.8.6 installed. Os - Windows Xp Sp2. I use the following code to fill TreeWidget: def updateTreeWidget(self, widget, results): """ Updates the widget with given results """ widget.clear() for…
oldPadavan
  • 190
  • 1
  • 5
  • 15
6
votes
2 answers

How to get the number of items of a QTreeWidget

I have created a QTreeWidget, I'm trying to list all the items displayed. I do not want to go inside the items if the item have child but not expanded. It's really getting the number of Items I can see in the tree. I have tried : for( int i = 0;…
Seb
  • 2,929
  • 4
  • 30
  • 73
6
votes
3 answers

How can I get notified of internal item moves inside a QTreeWidget?

I subclassed a QTreeWidget, set its dragDropMode to InternalMove and populated it with custom items, some of which can be dragged, others accept drops. The user can move items around the tree as expected. But I need to be notified of the change in…
neuviemeporte
  • 6,310
  • 10
  • 49
  • 78
6
votes
2 answers

How to implement itemChecked and itemUnchecked signals for QTreeWidget in PyQt4?

Where are the signals itemChecked and itemUncheсked on the QTreeWidget? Qt Signals: (quote from PyQt4 QTreeWidget documentation page) void currentItemChanged (QTreeWidgetItem *,QTreeWidgetItem *) void itemActivated (QTreeWidgetItem *,int) void…
Bruno Gelb
  • 5,322
  • 8
  • 35
  • 50
5
votes
2 answers

Qt widget resizes to width=256, while it shouldn't

Form setup: QSplitter (highlighted on the image) that contains QTreeWidget (left) and QTableWidget (right): Non-default properties of these two widgets within QSplitter: QTreeWidget minimumSize / Width = 150 QTableWidget minimumSize / Width =…
Andrejs Cainikovs
  • 27,428
  • 2
  • 75
  • 95
5
votes
2 answers

Individual QTreeWidgetItem indentation

Is it possible to have individual indentation of items in a QTreeWidget? In specific, I have have a column containing both text, icon and for some of them a CheckBox. The items without a CheckBox gets shifted to the left so the indentation of the…
Magus
  • 87
  • 1
  • 6
5
votes
1 answer

Sort a PySide.QtGui.QTreeWidget by an alpha numeric column

I would like to sort a QTreeWidget by the alpha_numeric column. Update: Following ekhumoro's example, I re-implemented the QTreeWidgetItem __lt__ method to use the desired natural sorting. Relevant code: class TreeWidgetItem(QtGui.QTreeWidgetItem): …
Brad
  • 191
  • 8
5
votes
2 answers

Qt model/view vs standard widget

I am currently reading model/view tutorial from Qt, but I am still not sure if I should use model/view or widget for my Qt program : I need to do a logger application that will monitor all information in a simulation environment. Basic scenario…
peterphonic
  • 951
  • 1
  • 19
  • 38
1
2
3
35 36