Results 1 to 8 of 8

Thread: Which QWidget is used to display the QVariant QAbstractTableModel::data(...) returns?

  1. #1
    Join Date
    Dec 2009
    Posts
    52
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Which QWidget is used to display the QVariant QAbstractTableModel::data(...) returns?

    Hello,

    I have a model, a view and a delegate, each sub classing QTableView QAbstractTableModel and QStyledItemDelegate.

    My model's data(...) function returns QString for 2 columns and a QStringList for the 3rd column.

    Which class chooses the QWidget to display the cell based on the QVariant returned by data(...)?

    Regards,

  2. #2
    Join Date
    Dec 2009
    Posts
    52
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Which QWidget is used to display the QVariant QAbstractTableModel::data(...) retu

    I realize now the only case handled is when data(...) returns a QString

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Which QWidget is used to display the QVariant QAbstractTableModel::data(...) retu

    Quote Originally Posted by hml View Post
    I realize now the only case handled is when data(...) returns a QString
    No, that's not true. Integers and dates (and anything that can be converted to a string) are handled nicely as well. You can't show a list with the default delegate, though, that's true.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Dec 2009
    Posts
    52
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Which QWidget is used to display the QVariant QAbstractTableModel::data(...) retu

    Can I register a "handler" for lists to the default delegate?
    I am using a custom delegate for editing anyways. But I want to change the DisplayRole widget....
    Is this doable?

    My work around has been to concatenate the list inside a QString. However, I get that QString in my delegate's setEditorData() as well, and now have to parse the QString to separate the items an use the individual items to set data in the editor widget.

    If I could pass around from model's data() to delegate's setEditorData() the QStringList as the QVariant, it would be much nicer.

    I can also write a different data() function of my specific model and have my delegate's setEditorData() not call the model base class data() but the concrete model's other data() function.

    Thank you,

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Which QWidget is used to display the QVariant QAbstractTableModel::data(...) retu

    Quote Originally Posted by hml View Post
    Can I register a "handler" for lists to the default delegate?
    Yes, of course.
    But I want to change the DisplayRole widget....
    The delegate doesn't use any widgets for DisplayRole. Only the editor is a widget.

    If I could pass around from model's data() to delegate's setEditorData() the QStringList as the QVariant, it would be much nicer.
    What prevents you from doing that?

    I can also write a different data() function of my specific model and have my delegate's setEditorData() not call the model base class data() but the concrete model's other data() function.
    But why? You can return any data you want from data() as long as it fits into QVariant. Also note you are not limited to the roles handled by the default delegate. Your delegate (and everything else involved into the architecture) can use custom roles to do its work.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Dec 2009
    Posts
    52
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Which QWidget is used to display the QVariant QAbstractTableModel::data(...) retu

    Ok,

    so you are saying reuse the data() function of the model, and instead of having my delegate's setEditorData() call the model's data() with Qt::EditRole, use the user-specific role as the "role" argument and then change data() to return QStringList or actually QMap in my case.

    I will then just ignore the EditRole in the model's data() because I assume the only who ever calls the data( ... EditRole) is my delegate...

    thanks,

    ps: perhaps you looked at my other post regarding the editor widget not hiding the cell displayed underneath,

    regards,

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Which QWidget is used to display the QVariant QAbstractTableModel::data(...) retu

    Quote Originally Posted by hml View Post
    so you are saying reuse the data() function of the model,
    Not "reuse". Just "use".

    and instead of having my delegate's setEditorData() call the model's data() with Qt::EditRole, use the user-specific role as the "role" argument
    and then change data() to return QStringList or actually QMap in my case.
    Yes, for that specific custom role.

    I will then just ignore the EditRole in the model's data() because I assume the only who ever calls the data( ... EditRole) is my delegate...
    I don't know if the only one but probably so. Of course if you are the only one using EditRole then you can return your map from that.

    ps: perhaps you looked at my other post regarding the editor widget not hiding the cell displayed underneath,
    No, but the behaviour is perfectly normal and documented.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Dec 2009
    Posts
    52
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Which QWidget is used to display the QVariant QAbstractTableModel::data(...) retu

    Thank you for your help,

    rds,

Similar Threads

  1. Convert QWidget to QVariant How to?
    By sergey_85 in forum Qt Programming
    Replies: 3
    Last Post: 15th December 2009, 07:21
  2. Replies: 1
    Last Post: 20th May 2009, 20:36
  3. QAbstractTableModel , custom data
    By akon in forum Newbie
    Replies: 0
    Last Post: 17th April 2009, 16:03
  4. QAbstractTableModel data insert issues
    By nategoofs in forum Qt Programming
    Replies: 1
    Last Post: 13th August 2007, 09:16
  5. QAbstractTableModel::data not being called...
    By steg90 in forum Qt Programming
    Replies: 1
    Last Post: 5th June 2007, 09:52

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.