0

I'm writing a messenger, and there is a message feed there. As you all know message feeds usually look like lists and go from bottom to top, the keep the scrolling positions anchored to the bottom when a new element is added, they grow upwards when resized and all kinds of fancy behavior like that.

So, I wanted to use QListView to make the feed, I have a model written elsewhere, it's absolutely under my control. But it doesn't seem like QListView supports this mode. There is a trick of how to do it with QML, but I don't have QML used anywhere else in my project and I'm not sure of how to interact with it, like how to set there my model, how to listen for signals or if it's going to behave well in my QGridLayout where I want it to place.

I can't believe no one ever faced the same situation. I'm trying to find the most standard solution, involving as little of my rookie code as possible, keeping in mind that Qt guys are much more experienced in layouting elements in list view and handling all corner cases. If I'm correct my options are

  1. Use QML for the feed
  2. Try to rotate QListView with QGraphicScene tricks
  3. Reimplement QListView

Which of those you think is a better solution? Or, may be, someone knows some better way to do it?

Blue
  • 186
  • 8
  • 1
    Which aspect are you failing to recreate, exactly? To me a messaging view just looks like a regular top-to-bottom list of items. Optionally you can force a scroll to the bottom every time a new message is added. – Botje Aug 12 '20 at 07:42
  • 2
    Maybe, this is helpful: [SO: Stop QTableView from scrolling as data is added above current position](https://stackoverflow.com/a/42460216/7478597) – Scheff's Cat Aug 12 '20 at 07:43
  • 2 Botje: there is a way to do it top-to-bottom style but it involves a lot of workarounds - like keeping the scroll to bottom when element adds to the bottom and you're looking there, but keeping it steady when it's not - so you need to precalculate the size of the shift for you to scroll the list after, also distinguishing user scrolls from this automatic ones and caused by resizes - it's kind of a drag, and the way I've done it before, I thought there was more elegant solution – Blue Aug 12 '20 at 07:49
  • 2
    O.T.: Instead of `2 Botje`, please, use `@Botje`. The latter results in a notification in the browser of Botje. – Scheff's Cat Aug 12 '20 at 08:00
  • 1
    @Blue Instead of rotating your view I suggest you should adjust your model. How? You can use `QSortFilterProxyModel` for this to not touch your main model. I am not sure if it is a good way in widgets interfaces, because I only use QML, but this proxy model is very helpful. – Maxim Skvortsov Aug 13 '20 at 15:02
  • 1
    @MaximSkvortsov I'm not so sure about that, you see - I can just sort them in my main one for the newest to be upper. My bigger concern is that annoying scrolling-positioning-resising-sticking-to-bottom-but-not-always maintaining issue and also the moment for the view to call canFetchMode/fetchMore methods when it reaches the top, not the bottom. – Blue Aug 13 '20 at 21:34
  • @Blue In this situation I see the only one good way - use `QAbstractItemView` and implement what you need. – Maxim Skvortsov Aug 13 '20 at 21:53
  • 1
    I took a quick glance on over 3k lines of QListView, as usual using whole private inheritance tree - the idea of just turning their list upside down using QGraphicsProxyWidget doesn't sound silly anymore :))) – Blue Aug 13 '20 at 21:58

0 Answers0