Results 1 to 6 of 6

Thread: Programatically add USerRole data to specific cell of QAbstractTableMode

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,349
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: Programatically add USerRole data to specific cell of QAbstractTableMode

    It is not clear to me how to add data with a custom role.
    All you have to do is define a new role with the value > Qt:: UserRole, then call setData() with the string you want to add and the new role.

    In the code you have posted above, the only time you save anything is when the role == EditRole. If you want setData() to save your string when the role == UserRole + 1, you must add an if () clause for that.

    QTableView does not know anything about user roles so it will never ask for it, but you can call data() on your model (or the model index) with this role whenever you want to get the value for your custom role.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  2. The following user says thank you to d_stranz for this useful post:

    franco.amato (27th November 2021)

Similar Threads

  1. Replies: 15
    Last Post: 15th August 2016, 22:08
  2. Disable a specific cell in QStandardItemModel
    By Omid123 in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2015, 12:52
  3. Replies: 1
    Last Post: 12th May 2013, 21:17
  4. Reformat data in cell
    By wirasto in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2009, 08:21
  5. setting UserRole data in QSqlTableModel
    By orgads in forum Qt Programming
    Replies: 1
    Last Post: 2nd June 2008, 09:40

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
  •  
Qt is a trademark of The Qt Company.