qtreeview

QTreeView with custom items

喜夏-厌秋 提交于 2019-12-19 04:05:58
问题 I'm writing my first Qt application with PySide and am having some trouble creating a custom tree view. I'd like to list my own data in one column. Each item must have text with tooltip, different text color, different background color, icons with actions and tooltip. The default tree works. I have view: class TreeView(PySide.QtGui.QTreeView): and model: class TreeModel(PySide.QtCore.QAbstractItemModel): How can I add different icons to my items? Here is my example: import sys from PySide

To set widgets on children items on QTreeView

喜欢而已 提交于 2019-12-18 17:28:19
问题 Thanks to this thread, I'm able to add widgets to 2nd or later column of QAbstractItemView (in my example QTreeView) of top level items of a view . But is it possible to add widgets to the children items? Here's what I've tried which partly went well: #!/usr/bin/env python import os from PyQt4.QtCore import QModelIndex, Qt from PyQt4.QtGui import QApplication, QItemSelectionModel, \ QPushButton, QStandardItem, \ QStandardItemModel, QTreeView from PyQt4.uic import loadUi class PrvTreeviewNest

Adding a right-click menu for specific items in QTreeView

ⅰ亾dé卋堺 提交于 2019-12-17 21:57:55
问题 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 example: for the tree elements with an even index. I tried adding a simple context menu with the following code: in the .h file: QStandardItemModel* model; QMenu* contextMenu; QAction* uninstallAction; private slots: void uninstallAppletClickedSlot();

QTreeView draw drop indicator

假装没事ソ 提交于 2019-12-13 12:07:02
问题 I need to implement rows moving via drag-n-drop in QTreeView and show the drop indicator between rows. I am wondering if there is a way to override indicator drawing, so it is displayed for all levels of hierarchy between rows only (not the rectangle around the item), the line must be as wide as the entire row (not as the one column). 回答1: It is possible by modyfing style used to draw widget. My attempt seemed to work well, but it's a bit of cheating the qt's style system, so i cannot

Editable reorderable (by drag and drop) Qt5 QTreeView example

主宰稳场 提交于 2019-12-13 05:43:21
问题 after being unable to find a decent generic hierarchical reorderable drag and drop example for Qt5's QTreeView, I tried to transform the Editable Tree Model example code accordingly. There's an related question recorded at: QTreeView with drag and drop support in PyQt, but while it's PyQt4, which isn't a problem in itself (I'm going to convert this to PyQt anyway ;)), the treeview + abstract model doesn't work properly. At least, it doesn't reorder any items here. This example code doesn't

What is the good way to lock/freeze columns in QTreeView

与世无争的帅哥 提交于 2019-12-13 02:11:20
问题 I am trying to implement frozen (those that don't scroll when the rest of the grid is scrolled horizontally) columns in a QTreeView - just like in Excel. I tried to find some native Qt way to freeze columns, but the only thing I could find is a side-mention in QAbstractScrollArea::setViewportMargins , as mentioned in this post. So I followed the suggestion in the answer to the post and overlaid another QTreeView looking at the same model on top. I.e. now I have 2 QTreeViews, one only showing

qt: QTreeView - limit drag and drop to only happen within a particlar grandparent (ancestor)

天涯浪子 提交于 2019-12-12 22:37:14
问题 I have a QTreeView in which I have implemented drag and drop to allow the re-ordering of items. GIven the following example of a tree: Food <--fixed |--Vegetables <--fixed | |--carrots <-- draggable/parentable | |--lettuce <-- draggable/parentable | | |--icebergLettuce <-- draggable but NOT parentable |--Fruit <-- fixed | |--apple <-- draggable/parentable | |--orange <-- draggable/parentable | |--bloodOrange <-- draggable/parentable etc... Anything marked as draggable may be dragged. Anything

one type of file format in QTreeView

本秂侑毒 提交于 2019-12-12 21:28:52
问题 Is it possible to set only one file format visible to the user? I'm searching it in documentation, but I can't find it... If not, which other widget you are suggesting to use? 回答1: I assume you're using a QTreeView with a QFileSystemModel. If not, I'd suggest doing so. QTreeWidget is not as flexible. QFileSystemModel has a method called setNameFilters that should do what you want. To use it, do something like this: QStringList filters; filters.append("*.cc"); // whatever filters you want

Hyperlinks in QTreeView

心不动则不痛 提交于 2019-12-12 20:48:38
问题 I'm trying to display clickable links within a QTreeView. I've created my own QStyledItemDelegate, and I can draw text that looks like a link, but isn't clickable like a link would be. One option I'm thinking of is creating a QLabel with a link, and drawing the QLabel inside the QTreeView cells. The only problem is that I can't figure out how to add QLabels to the QTreeView. Any ideas? 回答1: Have you checked out QAbstractItemView::setIndexWidget? You could create a QLabel like you said and

Set bold rows in a QTreeView

北战南征 提交于 2019-12-12 18:01:49
问题 I have a custom subclass of a QTreeView in a pyqt application. I'm trying to give the user the ability to highlight and "lowlight" (for lack of a better term) rows. Highlighted rows should have bold text and (optionally) a different background color. Any ideas? I'm considering StyleSheets as an option, but have so far been unable to get that to work. If I set the QTreeView's stylesheet: self.setStyleSheet("QTreeView::item:selected {border: 1px solid #567dbc;}") I can't figure out how to