Results 1 to 7 of 7

Thread: QTableWidget::editItem -- how to get pointer to the editor?

  1. #1
    Join Date
    Apr 2007
    Location
    Toruń, POLAND
    Posts
    24
    Thanks
    7
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QTableWidget::editItem -- how to get pointer to the editor?

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget::editItem -- how to get pointer to the editor?

    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

  3. #3
    Join Date
    Apr 2007
    Location
    Toruń, POLAND
    Posts
    24
    Thanks
    7
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QTableWidget::editItem -- how to get pointer to the editor?

    Marcel, thank you for your answer.

    Quote Originally Posted by marcel View Post
    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.

    Quote Originally Posted by marcel View Post
    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-p...them-7653.html

    have a nice day, bye

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget::editItem -- how to get pointer to the editor?

    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

  5. #5
    Join Date
    Apr 2007
    Location
    Toruń, POLAND
    Posts
    24
    Thanks
    7
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QTableWidget::editItem -- how to get pointer to the editor?

    Quote Originally Posted by marcel View Post
    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....
    Last edited by macias; 22nd June 2007 at 22:09.

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget::editItem -- how to get pointer to the editor?

    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

  7. #7
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget::editItem -- how to get pointer to the editor?


    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.

Similar Threads

  1. Model/View: Custom Persistent Editor
    By No-Nonsense in forum Qt Programming
    Replies: 2
    Last Post: 7th February 2007, 14:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.