PDA

View Full Version : QTableWidget and multiple editors -- how to get them?



macias
21st June 2007, 12:34
Hello,

Ok, I know how to create my own editors for QTableWidget, so I used QTextEdit and I created for each cell one editor (openPersistentEditor).
What design solution would you advice to maintain those:

a) each editor updates model data on each change -- I don't like it, it means, if user types a letter, with each letter I have to update data; advantage of this is I can pretend there is no editors when retrieving text from QTableWidget

b) make no updates, all data are kept in editors -- maybe it does not look elegant but it is efficient since there is no need for updates viewer<->model

The problem with (b) is I don't know if there is already some method in Qt to get the editor for given cell. I know it is created but how to get editor for cell (5,3)?
I could store all pointers to editors by myself but it is better not to reinvent the wheel so I am asking --

how to retrieve the editor associated with given cell in QTableWidget?

Comments on (a) vs. (b) are welcomed.

have a nice day, bye

jpn
25th June 2007, 17:57
I created for each cell one editor (openPersistentEditor).
Let's start with a question; do you really need persistent editors in every cell? They are a bit expensive to maintain so I'd advise against using them so extensively. How about simply adjusting edit triggers (http://doc.trolltech.com/4.3/qabstractitemview.html#editTriggers-prop) of the view so that an editor is opened for example whenever current item changes. The functionality should be pretty close to same but there would still be only one actual editor open at time.

macias
25th June 2007, 18:49
How about simply adjusting edit triggers (http://doc.trolltech.com/4.3/qabstractitemview.html#editTriggers-prop) of the view so that an editor is opened for example whenever current item changes.


Thanks for the link, I was unaware of this property.



Let's start with a question; do you really need persistent editors in every cell?


No, and yes. The aim is to deliver the most intuitive editor which is splitted into cells. Editor-on-demand would be sufficient, but there are several drawbacks:
a) when you click in the cell -- how do you get exact textual position? (you can calculate it by hand), persistent editor does it for you
b) you don't get back focus once you lost it (at least on KDE focus follows mouse policy) -- you move your mouse out of the window, you get back (but not over the table), no editing state; again -- persistent editor does the trick
c) it is rather a bug -- cell item rendering and editor rendering differs just a tiny bit, but it is enough to see the text is moving when clicked, and word wrapping sometimes is different; when you use persistent editors, there is no such problem, because all you see is table of editors

So I better stick to persistent editors -- anyway, in both cases I need pointer to editor and I managed to get that pointer via delegate.
Table delegate pass model index to created editor, when it is converted to persistent model index. I keep all the time (in the delegate) collection of created editors -- so I can query delegate to find for me editor for given model index.

Thank you for your help. have a nice day, bye