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

Draw on QTreeWidget With QPainter

I'm working on a little program and I have a bunch of panels in it. I want it so that when I focus into a panel, it draws a thin inline around it to show that it is focused. I got it working with all my panels except my tree view. Here's an example…
David Ludwig
  • 967
  • 2
  • 12
  • 26
2
votes
1 answer

How to hide the screenshot before releasing when dragging in QTreeWidget?

i want to hide the "dragging indicator"(the dragged row screenshot) only show mouse arrow when dragging in QTreeWidget, is it possible? i tried to reimplement mouseMoveEvent, the "dragging indicator" went away but at the same time , drag/drop is…
Shuman
  • 3,914
  • 8
  • 42
  • 65
2
votes
1 answer

stable sorting QTreeWidgetItems in QTreeWidget?

I have a list of QTreeWidgetItems (with children) in a QTreeWidget. I do not use a model for my data. From another window in my application the user can navigate thru the same set of data (viewed differently) and the QTreeWidget in the first window…
Magus
  • 87
  • 1
  • 6
2
votes
1 answer

QTreeWidget: renaming item to empty

just a quick and easy (maybe) question: How do I prevent an edit on a QTreeWidgetItem from allowing an empty string? Currently, I use QTreeWidgetItem::itemChanged(QTreeWidgetItem*, int) to check for modifications, and of course, I could just check…
senseiwa
  • 2,369
  • 3
  • 24
  • 47
2
votes
1 answer

PyQt4 Qtreewidget - get hierarchy text if child checkbox is checked

What I am currently trying to do is take a populated tree (qtreewidget) that has checkboxes at the bottom child level, and return the text of the path to the child if the box is checked. The reason I want to do this, is if a child is checked, it…
2
votes
1 answer

Qt QTreeWidget preserve sort

How do you implement a preserve sort in a Qt QTreeWidget? I.e. I would like the previous order of the tree preserved as much as possible. This allows the user to do something like click the "Name" column header and then the "Date" column header,…
Rusty
  • 1,095
  • 9
  • 15
2
votes
1 answer

Does QListWidget support grouping?

Is there a way of adding collapsible groups in QListWidget (as in windows7 explorer icon view). Or can we modify QTreeWidget to have similar behavior ?
rmi
  • 532
  • 4
  • 15
2
votes
1 answer

Showing filesystem in QTreeWidget

I have a simple Question. I want to show my filesystem in a QTreeWidget just like an common file explorer. How can i achieve that? I guess searching through all files and add them manual is not the approach to chose, right?
tuxmania
  • 906
  • 2
  • 9
  • 28
2
votes
0 answers

QTreeView: Drag-And-Drop fails to call QAbstractItemModel::dropMineData (source code in the post)

I am building an app with a treeview and I created a model which derives from QAbstractItemModel. I can manipulate the tree by dropping a file (dragging the file from outside of the app into the app) and drag-and-drop items within the tree. The…
2
votes
1 answer

Correctly implementing QStyledItemDelegate

I have a class (EditorTagManager) that contains a QTreeWidget. During runtime, the tree can contain any number of tag items, all of which are checkable. I'm trying to add horizontal lines between the QTreeWidgetItems in order to make it clear that…
Will Kraft
  • 553
  • 1
  • 8
  • 23
2
votes
2 answers

Drag and drop between two QTreeWidgets

My problem is that I have two QTreeWidgets and I would like to do drag and drop from one to an other (and vice-versa). I am able of drag and dropping QTreeWidgetItems, but, when I drop a QTreeWidgetItem that has children, I lose them and only the…
excalibur1491
  • 1,201
  • 2
  • 14
  • 29
2
votes
1 answer

currentItemChanged signali is not gererated when clicking on check box of QTreeWidget

QTreeWidget is not working as expected when clicking on check-box of non-leaf item. My QTreeWidget has two level of child and each item in the tree widget can be checked (check-box is enabled for each item). In this QTreeWidget, leaf items are user…
2
votes
1 answer

Can i stylize QTreeWidgetItem like QCheckbox?

Can i stylize QTreeWidgetItem like QCheckbox? For my checkboxes style is: QCheckBox { spacing: 15px; } QCheckBox::indicator { width: 20px; height: 20px; } QCheckBox::indicator:unchecked { image:…
Noisee
  • 306
  • 2
  • 7
2
votes
1 answer

Tracking changes in QTreeWidget

I have an editable QTreeWidget and wish to update some internal structures every time the user edits an item. However, there's no signal emitted specifically when some item is changed. There is itemChanged(), but it's emitted not only when the item…
Daniel
  • 305
  • 1
  • 4
  • 13
2
votes
2 answers

QtGui QTreeWidgetItem setData holding a float number

I was wondering if I could keep float values in a QTreeWidgetItem? When I try to record numbers using setData(0,0,number) it rounds it up to 6 digits of precision which is not enough for me. I want to keep the exact float value for further…
Kiarash
  • 7,378
  • 10
  • 44
  • 69