Answer the question
In order to leave comments, you need to log in
QItemDelegate (how to make a table with widgets)?
Hello everyone
The task we have is the following - the table (QTreeView) should contain buttons in one of the columns.
Faced nasty MV limitations in Qt. Namely with the mechanism of delegates. The mechanism allows editing to be delegated to a third party widget, but does not allow presentation to be delegated to a third party widget. To change the representation, it is proposed to override the ::paint virtual method. Those. it is impossible to place an arbitrary widget in a table cell (if it is not being edited at the moment).
Yes, using ::paint() you can also draw a button in the view, but to press it you have to click twice - first go to editing (then the delegate will create the desired editor-button) and click on the button again. The decision is stupid and inconvenient. In addition, the widget will not react in any way to hovering with the mouse.
If anyone has encountered a similar problem, I will be very glad of your help.
Answer the question
In order to leave comments, you need to log in
As far as I know, there is no direct solution to this problem. But there are quite a few options on how to implement this.
1. Use QML. Here, there is an example . But I didn't understand him.
2. Add widgets for each row in treeView. The solution is actually quite crooked, because the problems of synchronization of widgets with the model immediately appear. The developers themselves write that
This function should only be used to display static content within the visible area corresponding to an item of data. If you want to display custom dynamic content or implement a custom editor widget, subclass QItemDelegate instead.In addition, it is likely that with the number of lines in the model of the order of several thousand, everything will start to slow down.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question