Results 1 to 2 of 2

Thread: How to set UserRole within setData for QStandardItem?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2014
    Posts
    98
    Thanks
    43
    Thanked 4 Times in 4 Posts
    Platforms
    Windows

    Arrow How to set UserRole within setData for QStandardItem?

    I am building a tree using QStandardItemModel and populating it with QStandardItems. I am wrapping some data about each item into an object that I then aim to set as the data with role = UserRole. I am presently doing the following:
    Qt Code:
    1. QStandardItem.setData(object, role = QtCore.Qt.UserRole)
    To copy to clipboard, switch view to plain text mode 
    My question is about the documentation for setData(). It says to call setData() with:
    Qt Code:
    1. QStandardItem.setData(value, role=Qt.UserRole + 1])
    To copy to clipboard, switch view to plain text mode 
    I am confused by the "+1".

    Since Qt.UserRole = 32, does the +1 mean I should set role to 33? This seems very strange, unless I have multiple different UserRoles to employ, in which case I thought I could start with 32, and go from there. But I don't, I just have one such userRole (for now). Can I use Qt.UserRole, or do I need to start with Qt.UserRole+1?

    So far I am just using Qt.UserRole, and it seems to be working ok, but I worry there is some corner case I will hit where the thing will blow up.
    Last edited by neuronet; 13th February 2015 at 01:40.

Similar Threads

  1. QFileSystemModel + UserRole
    By NIteLordz in forum Qt Programming
    Replies: 1
    Last Post: 14th January 2015, 17:39
  2. Using Qt::UserRole in the Model/View architecture
    By d_stranz in forum Qt Programming
    Replies: 8
    Last Post: 23rd January 2011, 16:13
  3. Replies: 3
    Last Post: 6th October 2010, 16:11
  4. Model/View one index.column as hidden UserRole
    By doitux in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2008, 12:08
  5. setting UserRole data in QSqlTableModel
    By orgads in forum Qt Programming
    Replies: 1
    Last Post: 2nd June 2008, 09:40

Tags for this Thread

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.