QComboBox different Item value when selected and in dropDown - qt

how to easily make duo QAbstractListModel × QComboBox (not reimplementing QComboBox)
so that item representation on selection differs from one on DropDownList
Background:
I have model (inherited from QAbstractListModel) which flattens other model derived QAbstractItemModel, which however represents tree structure
Items are in the same order as they are in the tree model
I wanted to indent them, for better orientation in selection,
however once selected, it looks strange, when the sole selected item is indented
i.e. having this structure (verbatim how I assume it being seen in QComboBox DropDown list
parent 1
-> child 1.1
---> subChild 1.1.1
-> child 1.2
-> child 1.3
---> subChild 1.3.1
---> subChild 1.3.2
parent2
and once selected, I want it to show only
subChild 1.3.2
now it shows
---> subChild 1.3.2
as far as I know, both representations go through model::data(index, role=Qt::DisplayRole), so I can't differentiate them there
PS: In case there is some QComboBox-like directly working with models containing trees, even better

Related

What is the purpose of TreeView.isTreeNode

The TreeView attaches some properties to its delegate. One of them is isTreeNode. The documentation writes about isTreeNode:
required property bool isTreeNode - Is true if the delegate item represents a node in the tree. Only one
column in the view will be used to draw the tree, and therefore, only
delegate items in that column will have this property set to true. A
node in the tree should typically be indented according to its depth,
and show an indicator if hasChildren is true. Delegate items in other
columns will have this property set to false, and will show data from
the remaining columns in the model (and typically not be indented).
What is the benefit of this property? For me it looks like an alias for column == 0.
It's currently an alias for column === 0, like you say. But it makes the delegate more readable, and opens up for the possibility to rearrange columns at a later point, and improve the support for right-to-left layouts.

Display a QFileSystemModel in two Views: Tree View and a TableView/ListView of selected items

I have a model derived from QFileSystemModel. I extended it by a Role which holds a bool value which indicates whether a file has been selected for later use. This model is displayed in a qml TreeView. In this view I can select files via checkboxes. I have a list of QPersistentModelIndex of the selected indices stored in my model.
In a different view (probably a ListView or TableView), I would like to display only items, which have have been selected in the TreeView. In this other view I also want to be able to remove the selection. So the question is whether this can be done with only one model (or maybe a QSortFilterProxyModel inbetween) or whether I need to have two models communicating with each other.

QTreeView multiple issues (row hover highlights, child row highlights, row selection with multiple columns)

Versions
pyqt5
python 3.6
Setup
I'm having a few issues with the QTreeView class.
The QTreeView is configured as:
treeView.setSelectionBehavior(QAbstractItemView.SelectRows)
treeView.setSelectionMode(QAbstractItemView.SingleSelection)
There are no custom style sheets on this QTreeView
I've implemented a custom model for the view, and the flags() definition is:
def flags(self, index):
if not index.isValid():
return 0
f = super(RecordTreeModel, self).flags(index)
f = f | Qt.ItemIsSelectable | Qt.ItemIsEnabled
return f
Is there anything else relevant to the situation? I'm not doing anything fancy with my model. No custom painting, no special selection requirements -- everything is straight out of basic model examples besides the way the data structure is accessed.
Issues
Row Selection
When clicking on any column besides the first column, the row will not be selected.
Column Hovering
When hovering over any column besides the first column, the row will not be highlighted
Child Hovering
No child rows are ever highlighted when the mouse hovers over them.
I've been banging my head (and google's search bar) against these problems for several hours, to no avail.
Please let me know if I can provide any additional information!

Inserting QTable in QTree

I would like to design a particular layout using QTable inside of QTree. See the followng wireframe :
Is it possible to do this, knowing that in number :
The first node under Dialog 1 is seperated in 3 (or maybe four). The time, followed by an avatar icon, followed by a blue bubble with text and followed by a number (in my exemple, 75) So, first question, is it possible to have a tree node separated in four?
Section 2 is composed of leaf nodes and these nodes are QTable. So, question number 2, is it possible to create QTable embedded inside a QTree?
You can use the setItemWidget function in order to set the widget you wish for every tree widget item you wish.
In case of a QTreeView you should use the setIndexWidget function.

Setting multiple selection in QTreeView

I have a need here regarding multiple selection of items in the QTreeView. I have two widgets, QTreeView on left and another QGLWidget on the right. If I do a multiple selection, I must highlight the items in the glwidget. Vice versa, I need to highlight the items in the tree view if multiple selection is done on the glwidget. Currently, I am able to update single item by setting the current index of the tree view. Any ideas on how to update the selection of multiple items on the tree view with multiple selection on glwidget?
You can use the tree view's item selection model (treeView->selectionMode(), of type QItemSelectionModel). It has a signal selectionChanged() you can connect to to receive tree view selection changes and apply them to the GL view.
When receiving selection events from the GL view, you can use QItemSelectionModel::select() to propagate them to the tree view.
To enable multiselection on your treeview, call setSelectionMode( MultiSelection ).
Frank was faster, but I still post my (untested) code example for adding an item to the current selection:
treeView->selectionModel()->select(
treeView->model()->index(row, column, parent),
QItemSelectionModel::SelectCurrent);
There are other selection modes too, see the QItemSelectionModel reference. SelectCurrent is a short-hand for Select | Current, so means update current selection by selecting the given items. It does not mean "select as current selection" (replacing previous selection).
In Python (PyQt6) I do :
ui.my_treeView.setSelectionMode(ui.my_treeView.selectionMode().MultiSelection)
It works well.

Resources