PDA

View Full Version : QTableWidget::editItem -- how to get pointer to the editor?



macias
22nd June 2007, 12:59
Hello,

In QTableWidget is a method "editItem", however it does not return the created editor (quite contrary in Qt3 AFAIR). How to get the pointer to this editor?

have a nice day
bye

marcel
22nd June 2007, 20:02
You cannot obtain it from a QTableWidget.
Use a QTableView instead and create the editor with the default item delegate, using:
QAbstractItemView::itemDelegate and QAbstractItemDelegate::createEditor.
The latter will also return a pointer to the editor.

Regards

macias
22nd June 2007, 20:28
Marcel, thank you for your answer.


You cannot obtain it from a QTableWidget.
Use a QTableView instead and create the editor with the default item delegate, using:
QAbstractItemView::itemDelegate and


This method is available in QTableWidget too.



QAbstractItemDelegate::createEditor.
The latter will also return a pointer to the editor.


I use my own delegate already, but if I call directly createEditor I maybe miss some internals of editItem, I don't know.

Is there is a guarantee, that
editItem() is 100% equivalent of itemDelegate()->createEditor() ?

I read and I read Qt documentation but I cannot find any way to connect somehow table with editor (so table will know about the editor) or editor with table.

The same problem as for editItem I have with openPersistentEditor -- vide my other post here:
http://www.qtcentre.org/forum/f-qt-programming-2/t-qtablewidget-and-multiple-editors-how-to-get-them-7653.html

have a nice day, bye

marcel
22nd June 2007, 20:35
Is there is a guarantee, that
editItem() is 100% equivalent of itemDelegate()->createEditor() ?


It is not identical. You will still have to call editItem to start editing. But you will also have a pointer to the editor.

To see how the default editor is created you can look in the sources and create it like just they do.

Regards

macias
22nd June 2007, 22:01
It is not identical. You will still have to call editItem to start editing. But you will also have a pointer to the editor.

To see how the default editor is created you can look in the sources and create it like just they do.

Regards

I hesitate to use such code -- porting really tiny app from Qt3 to Qt4 is an ordeal (imho) and it is still not finished. I am afraid that by using such "hacks" as duplicating Qt source I am at even greater risk when I will port app from Qt4 to Qt5. So what I need is a "legit" way to get the table<->editor connection.

But don't get me wrong -- I appreciate your help! Thank you.

have a nice day, bye

PS. I think I will manage to do it manually -- after creating a delegate in table I can add some method to set which table it is, so delegate will know about table. So when createEditor is called I could pass an extra parameter for this editor, or notify table about the editor.
Ugly, but since there is no nice method in Qt....

marcel
22nd June 2007, 22:07
I hesitate to use such code -- porting really tiny app from Qt3 to Qt4 is an ordeal (imho) and it is still not finished. I am afraid that by using such "hacks" as duplicating Qt source I am at even greater risk when I will port app from Qt4 to Qt5. So what I need is a "legit" way to get the table<->editor connection.

Have it your way, but this is not a hack since it uses the interface provided by Qt.
I suggested to create the editor as in the Qt sources because you needed something like the default editor.

So, the bottom line is that this is not a hack. It just means you adapt to the new changes, even if it means making more and unexpected modifications.

Regards

marcel
22nd June 2007, 22:20
:)


PS. I think I will manage to do it manually -- after creating a delegate in table I can add some method to set which table it is, so delegate will know about table. So when createEditor is called I could pass an extra parameter for this editor, or notify table about the editor.
Ugly, but since there is no nice method in Qt....


This is a hack.