qtreeview

QAbstractItemModel and QTreeView [closed]

浪尽此生 提交于 2019-12-05 06:28:00
I need working examples (c++) of show own data model in QtreeView. Nathan Pitman There's a pretty good QTreeView/QAbstractItemModel example here . It's fairly straightforward once you get used to QT's ultra-generic model... just don't expect it to be as simple or obvious as Java's TreeModel. 来源: https://stackoverflow.com/questions/4354515/qabstractitemmodel-and-qtreeview

QTreeView remove decoration/expand button for all items

大兔子大兔子 提交于 2019-12-05 02:56:36
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... This is what I've done in the past for this problem, it's a bit of a hack but it's worked pretty well. In this case none.png doesn't exist. treeView->setStyleSheet( "QTreeView::branch { border-image: url(none.png); }" ); See https://forum.qt.io/topic/4767/how-to-get-rid-of-expande-collapse-qtreewidgetitem-indicator This got rid of the top level ones

Custom text color for certain indexes in QTreeView

落花浮王杯 提交于 2019-12-04 23:20:33
问题 I would like to draw texts in one of the columns in a QTreeView widget using a custom color (depending on the data related to each row). I tried to overload the drawRow() protected method and change the style option parameter like this (a stripped-down example): virtual void drawRow(QPainter* p_painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { QStyleOptionViewItem optionCustom = option; if (index.column() == 2) { optionCustom.palette.setColor(QPalette::Text, Qt:

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

元气小坏坏 提交于 2019-12-04 22:51:23
问题 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 able to have the user select the data (doubleclicking is going to execute another method). I am not certain how to make it readonly but also selectable. I am using the QStandardItemModel with the QStandardItem to hold the data. Any help would be much

QTreeView memory consumption

北城以北 提交于 2019-12-04 22:41:24
问题 I'm testing QTreeView functionality right now, and i was amazed by one thing. It seems that QTreeView memory consumption depends on items count O_O. This is highly unusual, since model-view containers of such type only keeps track for items being displayed, and rest of items are in the model. I have written a following code with a simple model that holds no data and just reports that it has 10 millions items. With MFC, Windows API or .NET tree / list with such model will take no memory, since

QTreeView with fixed column widths

ⅰ亾dé卋堺 提交于 2019-12-04 19:48:18
Today I'm trying to configure a QTreeView to fit my requirements. My view has basically three columns. The second and third column should be exactly 50 pixels wide no matter, what might be widgets size. The first column should occupy the remaining space. If I enlarge my widget the first column should automatically occupy the need free space, whereas the second and third column should retain their given widths of 50 pixels. This is what I tried so far: main.cpp #include <QApplication> #include <QTreeView> #include <QDebug> #include <QStandardItemModel> #include <QHeaderView> #include

QFileSystemModel setRootPath

折月煮酒 提交于 2019-12-04 17:52:15
问题 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 also attempted using this code When i run the application, instead of showing the content of the “/Users” Folder, it shows the root drive (note: not the content of the drive). The folder does exist and i also tried using other folders. 回答1: Did you

Python object in QMimeData

时光毁灭记忆、已成空白 提交于 2019-12-04 17:25:22
I'm implementing drag and drop QTreeView based on my custom model. All works fine, my tree displays data, drag and drop is enabled and now the last step lies ahead of me - to drop and trasfer dragged data. To do this I need to implement mimeTypes, mimeData and dropMimeData methods in my model. And now my question: Is there any easy standard way how to pass an arbitrary Python object through QMimeData? I'm doing just an internal move within QTreeView which displays hierarchy of my Python classes Person. And I want to reorder them. No drag and drop outside the application, not even outside of

Adding Vertical headers to a QTreeView

核能气质少年 提交于 2019-12-04 12:38:59
I have a QTreeView subclass (and QAbstractItemModel subclass) which has a nice horizontal header. I would like to add vertical headers (going down the left side) to match. But unlike QTableView which has separate vertical ( setVerticalHeader() ) and horizontal headers ( setHorizontalHeader() ), QTreeView only allows a single header ( setHeader() ). I know that I can just pretend that the leftmost column is the header and render it with a different background color (I don't need the ability to resize or rearrange the rows, so I wouldn't have to implement any of those special behaviors). But

Hyperlinks in QTreeView without QLabel

与世无争的帅哥 提交于 2019-12-04 12:16:24
I'm trying to display clickable hyperlinks in my QTreeView. I was able to do this using QLabels and QTreeView.setIndexWidget per the recommendations from this question. Hyperlinks in QTreeView Unfortunately, my QTreeView can be rather large (1000s of items), and creating 1000s of QLabels is slow. The upside is that I can use a Delegate in my QTreeView to draw text that looks like hyperlinks. This is super fast. The problem now is that I need them to respond like hyperlinks (i.e. mouseover hand cursor, respond to clicks, etc.), but I'm not sure what the best way to go about that is. I've been