Results 1 to 3 of 3

Thread: QTableView and QStyledItemDelegate ownership

  1. #1
    Join Date
    Jan 2011
    Posts
    32
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTableView and QStyledItemDelegate ownership

    I have a QTableView under which I am showing several different QSqlTableModel's (in succession, of course, not all at once). I am using a host of delegates to get the views the way that I want them.

    I am presuming, as setItemDelegateForColumn() is a member of QTableView, not QSqlTableModel, that once I set a delegate, then change models, my delegate is still with the view, and it has to be cleared out/deleted/whatever to line up with the new model.

    Am I correct in thinking this, or do the delegates actually stay with the model?

  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: QTableView and QStyledItemDelegate ownership

    Delegates are view related not model related. A quick experiment/code inspection confirms that delegates stay set despite changing the viewed model. Shrinking the column count even leaves delegates on the higher column numbers alone until the column count increases again.

    If you do change them be aware that:
    Any existing delegate will be removed, but not deleted. QAbstractItemView does not take ownership of delegate.

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

    lxman (7th July 2011)

  4. #3
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QTableView and QStyledItemDelegate ownership

    Quote Originally Posted by lxman
    Am I correct in thinking this, or do the delegates actually stay with the model?
    Yes, delegate remains with view, If you look at the dependencies,

    - View depends on Model
    - View depends on Delegate
    - Delegate depends on Model
    - Model in independent of View and Delegate
    - Delegate in independent of View

    So when you change the Model for a given View (say from Model1 to Model2), then you should be also the changing the Delegate for that corresponding Model.

  5. The following user says thank you to Santosh Reddy for this useful post:

    lxman (7th July 2011)

Similar Threads

  1. Remove ownership of QTableWidgetitem from Qtablewidget
    By deepal_de in forum Qt Programming
    Replies: 5
    Last Post: 7th May 2011, 06:36
  2. Replies: 3
    Last Post: 14th May 2010, 23:00
  3. Thread Ownership Problem
    By tntcoda in forum Qt Programming
    Replies: 1
    Last Post: 9th June 2009, 00:18
  4. Replies: 1
    Last Post: 9th February 2008, 12:46
  5. Replies: 2
    Last Post: 31st May 2006, 21: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.