PDA

View Full Version : TableView Delegate questions



No-Nonsense
8th December 2006, 15:18
1. I implemented QItemDelegate to create some custom widget to edit data from my custom model. How can I get the QTableView to display this editor delegate even if the user is not editing the cell?
In the Qt Icons Example openPersistentEditor(item) is used. But I want to have this behaviour for one column/the delegate. Is there another way to do this?

2. How can I call resizeRowToContents(int) when the editor delegate is shown (to make the cell fit the editor widget size) and after the editor is deleted? I would like the tableView resize dynamically when showing the editor.

Thanks in advance,
-Jens

wysota
8th December 2006, 23:25
1. I implemented QItemDelegate to create some custom widget to edit data from my custom model. How can I get the QTableView to display this editor delegate even if the user is not editing the cell?
In the Qt Icons Example openPersistentEditor(item) is used. But I want to have this behaviour for one column/the delegate. Is there another way to do this?

openPersistentEditor will open an editor provided by the delegate. Alternatively you could make a "snapshot" of the editor and render the snapshot instead of the actual widget when the user is not editing the item.


2. How can I call resizeRowToContents(int) when the editor delegate is shown (to make the cell fit the editor widget size) and after the editor is deleted? I would like the tableView resize dynamically when showing the editor.

This is not really a good idea. It is the editor which should integrate nicely into the existing layout, not vice versa. If you really want such a behaviour, you'll have to store a pointer to QTableView while creating the editor (the parent of the editor will be the viewport and the parent of the viewport should be the view).

No-Nonsense
11th December 2006, 09:27
openPersistentEditor will open an editor provided by the delegate. Alternatively you could make a "snapshot" of the editor and render the snapshot instead of the actual widget when the user is not editing the item.

Is there another way to show the persistent editor than calling openPersistentEditor for every index in the collumn? Does the View keep track of the cells in view and opens/closes the editors as needed or does all the persistent editors stay open? This would result in rowCount widgets being created...

How would I make a snapshot and render it? Rendering would be done in the paint method of my delegate?


This is not really a good idea. It is the editor which should integrate nicely into the existing layout, not vice versa. If you really want such a behaviour, you'll have to store a pointer to QTableView while creating the editor (the parent of the editor will be the viewport and the parent of the viewport should be the view).

The problem is that the custom widget to show inside the cell consists of 16 checkboxes layouted 2x8. They simply do not fit the cell height. Should I show an editing dialog instead?

Thanks in advance,
-Jens

wysota
11th December 2006, 09:39
Is there another way to show the persistent editor than calling openPersistentEditor for every index in the collumn? Does the View keep track of the cells in view and opens/closes the editors as needed or does all the persistent editors stay open? This would result in rowCount widgets being created...
Persistent editors are called persistent, because they are... persistent - so all open editors will stay open. What do you need a persistent editor for if you don't want it to be persistent? Maybe you can use a regular editor instead?


How would I make a snapshot and render it?
Just grab a pixmap from the editor before it is closed and render it or use QStyle if you wish to use one that composes from default widgets as your editor.


Rendering would be done in the paint method of my delegate?
Yes.


The problem is that the custom widget to show inside the cell consists of 16 checkboxes layouted 2x8.
So?


They simply do not fit the cell height. Should I show an editing dialog instead?
If the editor is complex then better use a separate dialog. You'll avoid cluttering the view.