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

QTreeWidget editItem fails with "edit: editing failed"

I have a QTreeWidgetItem added to a QTreeWidget: QTreeWidgetItem* item = new QTreeWidgetItem(ui->trwPairs); item->setFlags(item->flags() | Qt::ItemIsEditable); If the item is edited, I want to do a few checks on the new value: Pairs::Pairs(QWidget…
Drise
  • 4,310
  • 5
  • 41
  • 66
5
votes
2 answers

Populate QTreeWidget with hierarchic structure from absolute filepaths

I have a file which has absolute filepaths listed, 1 per line. The listed files are in order, so all files in e.g. the /Documents/ dir will be listed after eachother in the file. What I want to do is to place all these files in a QTreeWidget in a…
Bazze
  • 765
  • 10
  • 18
4
votes
2 answers

Iterating through QTreeWidget Nodes

As I posted several times over the past few months, I'm writing a journal/diary application in Qt. Entries are sorted in a QTreeWidget by year, month, day, and entry (default config that sorts entries by day) or by year, month, and entry (where all…
Will Kraft
  • 553
  • 1
  • 8
  • 23
4
votes
1 answer

Clear selection when clicking on blank area of Item View

I made a tree structure with QTreeWidget, and it works well. But I have a problem with that. Commonly, with a tree structure, if I want to deselect all, I click on a blank area of the tree-widget. But QTreeWidget does not seem to support that (or I…
Hyun-geun Kim
  • 919
  • 3
  • 22
  • 37
4
votes
1 answer

How do I stop the QTreeWidget from moving the scroll position?

I have a QTreeWidget with a bunch of QTreeWidgetItems. Each item has a couple columns. When one of the columns is wider than the width of the widget, there will be a scroll bar at the bottom. When I click on a QTreeWidgetItem inside the column that…
Di Zou
  • 4,469
  • 13
  • 59
  • 88
4
votes
1 answer

Dropping an external file into a QTreeWidget

I guess the implementation isn't quite the same for a QTreeWidget, but I'd like to be able to drop an external file, particularly an image or movie file into my QTreeWidget. I'm not trying to drag it into a specific QTreeWidgetItem, but rather just…
Cryptite
  • 1,426
  • 2
  • 28
  • 50
4
votes
1 answer

Suppress PyQt event temporarily?

I'm populating a branch of a QTreeWidget and then setting the expanded attribute on the parent of the branch to true. The itemExpanded signal fires in response, which is not what I want. Is there a temporary way to suppress or absorb signals during…
iwonder
  • 97
  • 2
  • 5
4
votes
3 answers

Do you need to delete widget after removeItemWidget from QTreeWidget?

I have a QTreeWidget with two columns: one for property name and one for property value. The value can be edited via a widget. For example one property is Animal. When you double click the property value column I make a (custom) combobox with…
C. Binair
  • 419
  • 4
  • 14
4
votes
3 answers

Repaint QTreeWidget

I have a simple class based on QTreeWidget. In some cases (when value one of columns updated), I need to repaint it. I have a function which invokes when I need to update my widget: void TreeWidget::updated() { /* some actions with cells */ …
garbart
  • 55
  • 4
4
votes
0 answers

FIXED: QTreeWidget change the branch hover style when hovering over an item

Im working on a project (big and complex) that i have to re-style using CSS and c++. For this project there is a custom QTreeWidget that must look like this: The question is, how i can change the hover background color of the "arrow"/ indicator,…
4
votes
2 answers

How to Get Absolute Path of Currently Selected Item in QTreeWidget on mouse Clicked

I have a simple QTreeWidget pointing to the root directory: #include #include #include int main(int argc, char **argv) { QApplication application(argc, argv); QStringList fileNames{"TEST/branch",…
oğuzhan kaynar
  • 77
  • 1
  • 10
4
votes
2 answers

QTreeWidget : disable a line but not the subtree

I use a QTreeWidget that shows a file listing so that a user can copy files to a directory. I want to disallow the user to copy the files to the same directory. Thus, I want to disable just one line in my QTreeWidget so that it is not selectable. I…
Tangui
  • 3,626
  • 2
  • 26
  • 28
4
votes
0 answers

Why isn't my Qt eventFilter picking up mouse events?

I have basically this code to intercept certain QTreeWidget events. MyWidget :: MyWidget () { m_tree = new QTreeWidget (); // ... m_tree -> installEventFilter (this); } bool MyWidget :: eventFilter (QObject * obj, QEvent * e) { …
spraff
  • 32,570
  • 22
  • 121
  • 229
4
votes
1 answer

Disable only one item in QTreeWidget

I have a QTreeWidget that can have many rows but only 3 columns: In the picture I have selected my last column. What I would like to do, is to disable the last column for every item in the tree UNLESS it is selected. So in my situation only the…
Łukasz Przeniosło
  • 2,725
  • 5
  • 38
  • 74
4
votes
2 answers

qt/c++ context menu - disable an item

I'm currently developing an app such as the browser using Qt and c++. I have create a contextual menu to allow on right click action such as delete, rename and add folder. void MyTreeWidget::createContextMenu() { contextMenu = new QMenu(); …
Seb
  • 2,929
  • 4
  • 30
  • 73
1 2
3
35 36