Nominate our 2022 Qt Champions!

using pixmaps as an alternative to openPersistentEditor() in an itemView

  • I have an item view where my editor, as dictated by my delegate, is identical to the way the item is painted in the view, when not being edited. Imagine having, inside an. tableView item, a composite widget with a lineedit, 2 QDials, some buttons etc. It is this widget that should be both the editor but also the persistent display of the item.

    I am looking for the best way to draw a lot of these widgets (the view will be in a scroll area), and i could have up to maybe 600 of these widgets open at once. Because the number of potential widgets is quite high, i dont see setIndexWidget() as being the right solution. The same goes for openPersistentEditor().

    My current idea is to use grab() on the editor when editing has finished, and save the pixmap. Then, whenever the delegate needs to paint the item, it is this pixmap that is drawn - instead of redrawing actual widgets. Without having implemented this, i imagine that this should be a lot more efficient than having hundreds of active widgets.
    This solution would therefore mean that only selected items will have an editor drawn for them, whilst all other items will have a pixmap drawn, that looks identical to the editor.

    I wanted to get some input on whether this is a good solution, or if i'm missing something obvious.

    Best regards

  • Moderators

    I'm doing something similar in sort of objects property tree. It works pretty well for large number of items. Definitely a massive win over a widget per item approach.
    One difference to your approach is that I don't use grab(), but instead have the editors created by the delegate a static drawing function that uses QStyle::drawControl and friends to draw an image of itself. This is because I don't want to instantiate all the editor widgets upfront to grab them (I have a bunch of them and it takes time). It's sort of a trade-off because it can get out of sync with the actual widget look. Whether this is something you'd be interested in or not is up to you, but the general idea of drawing an image is a valid one.