I'm waiting. Looks very promising. Those Delegate* types are your own, are they?
I'm waiting. Looks very promising. Those Delegate* types are your own, are they?
Yes, they are mine.
Here is the current state:
delegatelayout1.png
How is this going? I got assigned back to the task at least for some time so I can now introduce improvements.
Are you interested only in the display of items or also about editing and interaction?
In that case I will post my current solution and provide a link to it during the weekend. You want to use it in a commercial project?
Well, I can tell you how I did it. I have a tree of items that models the structure of the delegate. Items in that tree are subclasses of "DelegateLayoutItem" which can be either subclasses of "DelegateLayout" (which currently can be just DelegateLinearLayout) or DelegateWidget that can be subclassed any way one wants (I have subclasses that offer text or image that comes from the model and static text or static pixmap). The basic idea is that each of them provides a sizeHint() implementation and a paint() implementation. Both of them take a model index and QStyleOptionViewItem instance. The rest is just to calculate sizeHint() down the tree for a specific index and item option and paint everything. Just like for regular widgets or graphics items. I don't respect size policies yet and I only respect right alignment for a vertical layout. There is no event forwarding yet but the same idea can be employed for it.
Here is a sample (not actual, I don't have the code with me right now) implementation of sizeHint:
Qt Code:
return option.fontMetrics.boundingRect(option.rect, 0, text).adjusted(-leftMargin(), -topMargin(), rightMargin(), bottomMargin()).size(); }To copy to clipboard, switch view to plain text mode
and a sample paint:
Qt Code:
void DelegateText::paint(QPainter *painter, const QModelIndex &index, const QStyleOptionViewItem &option, const QRect &rect) { painter->drawText(r, 0, index.data(m_role).toString()); }To copy to clipboard, switch view to plain text mode
That is interesting! But how scalable is that?
Since now I'm facing a much bigger thing of similar sort. We have a list (QAbstractListModel) of channels. The main window shows those channels in a vertical list-like widget. It is not done as a real list. Just looks and behaves like if it was.
But since I'm reworking that piece of code (and its me who introduced that QAbstractListModel instead of custom structures in the first place) I'm considering making it... well... better. The issue is that channel widget is quite a complex widget. Multiple buttons, various modes (influencing what is show within) and so on. The original issue was a playlist which is basically one of three variants of what can be inside that channel widget (surrounded with other controls). Would your solution still be well usable in that case? Now it is not only lots of drawing but also lots of user interaction.
Also I already have .ui files (from previous version) covering the channel widget and all its parts. So not using that would be a waste somewhat. On a plus side we moved to Qt5 as well. Sadly QML is not much of an option (even thou I would lie to try it) mostly due to .ui files being already there.
Hard to say. For ~15k items it takes some time to perform an initial layout but then I'm not noticing any slowdowns.
Considering that there is completely no optimisation, I think the speed is satisfactory.
A general answer is "probably yes" but it depends on your particular usecase. As a last resort you can always use QtQuick.Since now I'm facing a much bigger thing of similar sort. We have a list (QAbstractListModel) of channels. The main window shows those channels in a vertical list-like widget. It is not done as a real list. Just looks and behaves like if it was.
But since I'm reworking that piece of code (and its me who introduced that QAbstractListModel instead of custom structures in the first place) I'm considering making it... well... better. The issue is that channel widget is quite a complex widget. Multiple buttons, various modes (influencing what is show within) and so on. The original issue was a playlist which is basically one of three variants of what can be inside that channel widget (surrounded with other controls). Would your solution still be well usable in that case?
I don't see how that's relevant. You can place a QQuickView (or whatever it was called) in a widget (see http://blog.qt.digia.com/blog/2013/0...ndowcontainer/) and have your list view implemented in QtQuick.Sadly QML is not much of an option (even thou I would lie to try it) mostly due to .ui files being already there.
Well, numer of items is limited, few I guess at most. Its only that each item is a complex widget by its own.
Is it possible to have an ordinary .ui based widget in a QQuickView?
OK, so I guess this closes the topic at least for some time (until I will go deeper into implementation).
But to finish it: how complex it would be, in your opinion, to make a class similar to Q[List|Tree]Widget that instead of keeping the model internal, would take external model and a delegate for creating item widgets? Having such a class seems useful for me since I already have the model, have the widgets and creating delegate is trivial...
I'm not sure what you mean. It seems this is exactly what QListView, QTableView and QTreeView do.
Bookmarks