Questions tagged [qtreeview]

QTreeView is a class in Qt framework. It provides a default model/view implementation of a tree view.

A QTreeView implements a tree representation of items from a model. This class is used to provide standard hierarchical lists that were previously provided by the QListView class, but using the more flexible approach provided by Qt's model/view architecture.

The official Qt documentation can be found here for Qt 4.8 and here for Qt 5.

823 questions
68
votes
6 answers

How to make item view render rich (html) text in Qt

Suppose my model has items with the following string for Qt::DisplayRole blah-blah some text other blah I want QTreeView (actually, any item view) to render it like a rich text. Instead, item views render it like a pure text by…
Anthony Serdyukov
  • 4,268
  • 4
  • 31
  • 37
42
votes
1 answer

Adding a right-click menu for specific items in QTreeView

I'm writing a Qt desktop application in c++ with Qt Creator. I declared in my main window a treeView, and a compatible model. Now, I would like to have a right-click menu for the tree item. Not for all of the items, but for a part of them, for…
user1835297
  • 1,059
  • 2
  • 12
  • 24
29
votes
1 answer

QTreeView middle column fill width space instead of last column

How can do this: I already tried this way: view->header()->setResizeMode(INDEX_COLUMN_SKU, QHeaderView::Interactive); view->header()->setResizeMode(INDEX_COLUMN_NAME, QHeaderView::Stretch); view->header()->setResizeMode(INDEX_COLUMN_QUANTITY,…
Sebtm
  • 7,002
  • 8
  • 29
  • 32
23
votes
2 answers

Selecting a row in QTreeView programmatically

I have a QTreeView with QFileSystemModel as model. The QTreeView has SelectionBehavior set to SelectRows. In my code I read a dataset to select and then select them via: idx = treeview->model()->index(search); selection->select(idx,…
the JinX
  • 1,950
  • 1
  • 18
  • 23
23
votes
8 answers

HowTo restore QTreeView last expanded state?

What I have: QTreeView class with table data And connected QAbstractTableModel model Question: how to save expanded state of items? Is some one have finished solutions? PS: I know, that I can do this code by myself, but I don't have much time,…
mosg
  • 12,041
  • 12
  • 65
  • 87
15
votes
2 answers

How do you set the column width on a QTreeView?

Bear with me, I'm still new to QT and am having trouble wrapping my brain around how it does things. I've created and populated a QTreeView with two columns: class AppForm(QMainWindow): def __init__(self, parent = None): super(AppForm,…
ashground
  • 239
  • 2
  • 3
  • 10
15
votes
9 answers

Is it possible to deselect in a QTreeView by clicking off an item?

I'd like to be able to deselect items in my QTreeView by clicking in a part of the QTreeView with no items in, but I can't seem to find anyway of doing this. I'd intercept a click that's not on an item, but the QTreeView doesn't have a clicked…
Skilldrick
  • 69,215
  • 34
  • 177
  • 229
14
votes
1 answer

How to hide some columns in a QTreeView?

I have a QTreeView model, that model has four columns as the following (Name, Size, Type, Data Modified). I want is to remove the (Size, Type, Data Modified) columns, and leave only the column named Name. QFileSystemModel *sysModel = new…
Lion King
  • 32,851
  • 25
  • 81
  • 143
14
votes
2 answers

QFileSystemModel setRootPath

I am attempting to create a Qt application which shows the contents of a folder (“Users” folder in Mac OS). Here is the code: QFileSystemModel *dirModel = new QFileSystemModel; dirModel->setRootPath("/Users"); ui->listView->setModel(dirModel); I…
tanto
  • 339
  • 1
  • 2
  • 11
12
votes
1 answer

QTreeView with drag and drop support in PyQt

In PyQt 4 I would like to create a QTreeView with possibility to reorganize its structure with drag and drop manipulation. I have implemented my own model(QAbstractItemModel) for QTreeView so my QTreeView properly displays the data. Now I would like…
Ondrej Vencovsky
  • 3,188
  • 9
  • 28
  • 34
12
votes
2 answers

QTreeView remove decoration/expand button for all items

I want to have my QTreeView always expanded all of the items. In that case, all expand button / decoration are unnecessary and I want get rid of them. How can I delete all of them? setRootIsDecorated will only delete that buttons on first level...
GwynBleidD
  • 20,081
  • 5
  • 46
  • 77
11
votes
3 answers

Changing the row background color of a QTreeView does not work

I have a QTreeView and want different background colors for rows, depending on their content. To achieve this, I derived a class MyTreeView from QTreeView and implemented the paint method as follows: void MyTreeView::drawRow (QPainter* painter, …
SebastianK
  • 3,582
  • 3
  • 30
  • 48
10
votes
4 answers

Python: PyQt QTreeview example - selection

I'm using Python 2.7 and Qt designer and I'm new to MVC: I have a View completed within Qt to give me a directory tree list, and the controller in place to run things. My question is: Given a Qtree view, how may I obtain a directory once a dir is…
Harry Lime
  • 2,167
  • 8
  • 31
  • 53
10
votes
1 answer

PyQT -- How can you make a QTreeview uneditable but also selectable?

I just switched from wxPython to PyQT and I am having some trouble with the QTreeview. I have a QTreeview that will display data categorized into sections that are expandable, but the data in this TreeView should not be editable, but I need to be…
10
votes
1 answer

Easier way to find (visual) position of QModelIndex in QTreeView

I'm interested in calculating the physical position of a node in QTreeView and can't find a way to do this (other than calculating it myself, which is cumbersome and error prone given the robustness of QTreeView). Is there a standard way of finding…
Dan O
  • 4,323
  • 5
  • 29
  • 44
1
2 3
54 55