Results 1 to 3 of 3

Thread: QTableWidget and multiple editors -- how to get them?

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

    Default QTableWidget and multiple editors -- how to get them?

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTableWidget and multiple editors -- how to get them?

    Quote Originally Posted by macias View Post
    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 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.
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    macias (25th June 2007)

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

    Default Re: QTableWidget and multiple editors -- how to get them?

    Quote Originally Posted by jpn View Post
    How about simply adjusting edit triggers 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.

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

Similar Threads

  1. QTableWidget Sorting Multiple Selection
    By rhiacasta in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2006, 21:05

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.