Results 1 to 5 of 5

Thread: Subclass QStandardItem

  1. #1
    Join Date
    Aug 2015
    Posts
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Question Subclass QStandardItem

    Hello,

    I know there have been similar questions, but I did not find my specific problem. Well here is what I did:

    - subclassed QTreeView
    - subclassed QStandardItem: implemented clone() data() setData() type()
    - subclassed QStandardItemModel
    - subclassed QItemDelegate

    Now, what I wanted is that the delegate does not operate directly on the text the users sees (Qt::DisplayRole) but on the edit role (Qt::EditRole). I expected that when I set QStandardItemModel::setItemPrototype to my subclassed QStandardItem it will call the data() and setData() functions of the subclass.
    Well, this does not seem to be the case. It still uses the base class data() and setData() functions. Only when i also overwrote data() and setData() for my subclass of QStandardItemModel, then the behaviour was as expected.

    So, why is it necessary to call setItemPrototype() at all, when I have to overwrite data() and setData() for my subclass of QStandardItemModel anyways (and there I can use the correct type)? Also I found this by try-and-error, I don't think this is documented anywhere.

    Maybe someone has tried this before?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Subclass QStandardItem

    Did you add instances of your QStandardItem subclass when populating the model?

    Cheers,
    _

  3. #3
    Join Date
    Aug 2015
    Posts
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Subclass QStandardItem

    Quote Originally Posted by anda_skoa View Post
    Did you add instances of your QStandardItem subclass when populating the model?

    Cheers,
    _
    Yes. As explained, it seems to work after I implemented data() and setData() in the subclass of QStandardItemModel. I expected that setting the prototype with "setItemPrototype()" is enough, but it seems it is not and I don't know why.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Subclass QStandardItem

    Well, setItemPrototype() would have no affect if you added QStandardItem instances to your model, so I wanted to verify that you hadn't accidentally done that.

    I assume you have also checked that the signatures of the overloaded methods match exactly?

    Cheers,
    _

  5. #5
    Join Date
    Aug 2015
    Posts
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Subclass QStandardItem

    Quote Originally Posted by anda_skoa View Post
    Well, setItemPrototype() would have no affect if you added QStandardItem instances to your model, so I wanted to verify that you hadn't accidentally done that.

    I assume you have also checked that the signatures of the overloaded methods match exactly?

    Cheers,
    _
    Yes, they match.

    Edit: The problem was solved. It seems my project was not recompiled, after clean / build it works as expected. So everything is correct.
    Last edited by un; 14th August 2015 at 17:15.

Similar Threads

  1. Replies: 2
    Last Post: 15th April 2013, 07:33
  2. QStandardItemModel and QStandardItem
    By DmitryNik in forum Newbie
    Replies: 5
    Last Post: 9th October 2011, 18:17
  3. Tree without using of QStandardItem
    By NoRulez in forum Qt Programming
    Replies: 1
    Last Post: 12th July 2010, 13:23
  4. Replies: 8
    Last Post: 12th February 2010, 03:41
  5. QStandardItem question.
    By alexandernst in forum Qt Programming
    Replies: 6
    Last Post: 21st July 2009, 02:01

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.