Multiple widget in cells - design
-
Hi everyone!
I'm trying to build my first application based on Qt. I have discovered the whole pattern of Model/View/Delegate and I'm trying to build the application with the best Qt practices.
I have unfortunately not found any topic that answers exactly my problem.
I want to display information in a table with filters and with interactive content (all content is represented by text) in a specific column. By interactive, I mean : add text, delete text, modify text.
It might be a mimic of these examples : Bootstrap tags InputMy situation is the following :
- AbstractTableModel (based on a Python dictionary & subclassed data(), rowCount(), columnCount(), flags(), headerData() and setData())
- TableView
- SortFilterProxyModel (subclassed filterAcceptsRow(), data())
- StyledItemDelegate (on the specific column of the view)
In my mind, I have two solutions:
-
Draw control in the cells and rewrite everything related to mouse event (click, double click and position in the cell). I would do it in the paint() subclassed function. The main problem here is the mouse handling but the performance would be great.
-
Insert widget (and buttons inside the widget) in a cell. I might be able to click in the widget (with a subclass widget) and to click buttons. However, the performance would be catastrophic (15k rows). Also, I feel like i'm breaking the Qt pattern and it is specifically mentionned that this solution should be used for static content only.
Edit: I may have found a third solution:
- Use the QAbstractItemView::openPersistentEditor() function with a createEditor from my delegate. Thus, no problem of widget generation (on editor creation) nor storage (transparent) but still problems of performance.
Come the questions:
- What's is the best way to achieve my project from a Qt pattern point of view?
- If I go for the drawControl solution, how can i handle the position of the cursor from the cell perspective?
- If I go for the Widget Insertion solution, where is the best place to store/create them (not in the delegate::paint() function obviously) ?
Thank you for your reading and your time!
-
Hi everyone,
Little update of my progress:
- Using a persistent editor seems to be the best solution from my point of view
- It is completly transparent from the creation in paint() (calling openPersistentEditor -> createEditor) to its destruction (calling closePersistentEditor provoking a re-opening and a redraw of the editor)
- The editor, a custom widget, responds correctly after handling setModelData, updateEditorGeometry and editorEvent
I'm still not sure that is the good way to proceed but it works fine.
I'm closing the subject. Thanks for your reading.
-
Hi and welcome to devnet,
Not sure I'm following you correctly. Do you mean that you would like to have that kind of tag list inside cells of your table view ?
-
Hi everyone,
Little update of my progress:
- Using a persistent editor seems to be the best solution from my point of view
- It is completly transparent from the creation in paint() (calling openPersistentEditor -> createEditor) to its destruction (calling closePersistentEditor provoking a re-opening and a redraw of the editor)
- The editor, a custom widget, responds correctly after handling setModelData, updateEditorGeometry and editorEvent
I'm still not sure that is the good way to proceed but it works fine.
I'm closing the subject. Thanks for your reading.