Results 1 to 2 of 2

Thread: model view delegate

  1. #1
    Join Date
    Mar 2012
    Location
    china
    Posts
    54
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default model view delegate

    I want to display items in two QTreeView,both have Qt::CheckStateRole,but have different check statue,,they share the same Qt:isplayRole,QItemDelegate can't show the different check statue??

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: model view delegate

    The views display what is in the (presumably shared) model. You cannot have two distinct values returned to the views for the same item and role.

    You could implement a Qt::UserRole, holding a second Qt::CheckState value, in the model. Reimplement the delegate to paint the checkbox based on the "correct" role for the view. Reimplement the editorEvent() to handle setting the check box on the non-default view. It's quite a bit of work. Look at the Qt source for the QStyledItemDelegate for inspiration.

    It may be easier to adapt your model to have an extra column that mirrors the existing column. When asked for roles other than Qt::CheckStateRole return/set the same as for the base column. For the Qt::CheckStateRole return/set a different value. Hide one column in one view, the other column in the other.

    How you do it depends on the model.

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

    waiter (12th May 2012)

Similar Threads

  1. Qt delegate model data and view
    By giusepped in forum Qt Programming
    Replies: 0
    Last Post: 27th July 2011, 11:30
  2. Model/View/Delegate How gets setEditorData / setModelData
    By moviemax in forum Qt Programming
    Replies: 0
    Last Post: 11th July 2011, 11:29
  3. Replies: 9
    Last Post: 8th March 2011, 08:35
  4. Model-View-Delegate
    By hotdox in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2010, 13:20
  5. Model View - Delegate - setIndexWidget
    By starcontrol in forum Qt Programming
    Replies: 16
    Last Post: 2nd April 2008, 14:30

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.