J
J
jkrieger2014-12-31 16:31:09
Qt
jkrieger, 2014-12-31 16:31:09

Adding an extra line string with QAbstractProxyModel?

Task: display in QListView some list + 1 line ("add new element") with the ability to filter elements.
The current solution looks like this:
QListItemModel -> QSortFilterProxyModel (filtering) -> MyQAbstractProxyModel (adding a virtual string) -> QListView
MyQAbstractProxyModel code:
pastebin.com/BTdHyzQ8
In general, the code even works, but with one exception. When an element is clicked, the QListView must emit a clicked() signal. But it does not always generate it, after a time somehow, no patterns have been identified. Obviously, the problem is in the wrong QModelIndex (in case index.isValid() != True it should not generate a signal).
It was also noticed that there is a display artifact: when you hover over an element, it is not selected, as it happens if the QListView is set to another model.
Question: Where to dig? What is wrong?
PS:
Found a hack to get around the problem - added another QSortFilterProxyModel between MyQAbstractProxyModel and QListView, which just serves as a spacer. The artifacts are gone and the clicked signal is generated properly. But still wondering what could be the problem.
Also noticed that if the QListView is set to the original QListItemModel, then the problem also occurs.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question