Details
-
Suggestion
-
Resolution: Duplicate
-
Not Evaluated
-
None
-
None
-
None
Description
Hi,
"but you can inject a widget in a view using Q(Styled)ItemDelegate, doesn't that suite your needs?"
No, not quite.
It works just fine for simple things. Changing colors, text, icons, etc.. But it does not work nicely at all if you want to inject a QPushButton, or a dropdown or any of the other common widgets. You're just stuck re-implementing the paint, editorData and createEditor methods. At the very least! That is really inconvenient and very error prone when you just want to insert one of the common widgets.
Also, there is the QAbstractItemView::setIndexWidget method which is less painful then what i just described, but that method is also not idea since you'd have to iterate over your rows manually and inject what you want. It works, yes, but requires extra bookkeeping.
Therefore i'm requesting a new delegate type that takes away the boilerplate code and allows one to inject any widgets in a view with ease. Since it would be for any widget derived object, a name like "QWidgetDelegate" would be fitting.
I'd think the (pseudo) code to use this would look somewhat like this:
QTableView *view = new QTableView; view->setModel(...); QWdgetDelegate *widgetDelegate = new .... widgetDelegate->setWidget(new QPushButton); view->setItemDelegateForColumn(0, widgetDelegate);
Now the first column in every row should be a QPushButton.
I am aware that the widgets are quite done at the moment and this would be a new feature. Yet i think the widgets are still widely used and having this feature makes using views with custom components a lot easier!
The issue i see with this approach is when signals are emitted.
1. How would the user side connect to each signal?
2. If a signal is emitted, how would the user know from which QModelIndex the signal originated?
The first issue can probably be solved by using a QSignalMapper.
The second issue, i don't know yet.
Best regards,
Mark
Attachments
Issue Links
- duplicates
-
QTBUG-60226 Provide easy way to add widgets to views
- Reported