Results 1 to 6 of 6

Thread: QStandardItemModel and QStandardItem

  1. #1
    Join Date
    Sep 2011
    Posts
    45
    Thanks
    17
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Question QStandardItemModel and QStandardItem

    Hello!

    I have a question which concerns models and items in models and probably a bit QVariant. The question is: why will not appear a picture after executing the code presented bellow?

    Qt Code:
    1. QIcon ico(":/block.png");
    2. v1.setValue(ico);
    3. item2->setData(v1, Qt::DisplayRole);
    4. model->setItem(0, 0, item2);
    5. QTreeView *tv = new QTreeView;
    6. tv->setModel(model);
    7. tv->show();
    To copy to clipboard, switch view to plain text mode 

    And another question, which was born by my curiosity, is: Does QStandardItem class's method setData work only with primitive data, such strings, integers etc.? Does it depend on QVariant-class?

  2. #2
    Join Date
    Aug 2011
    Posts
    44
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows Symbian S60

    Default Re: QStandardItemModel and QStandardItem

    Try to use setIcon instead of item2->setData(v1, Qt:isplayRole);
    Does it work as expected?

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

    DmitryNik (9th October 2011)

  4. #3
    Join Date
    Sep 2011
    Posts
    45
    Thanks
    17
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QStandardItemModel and QStandardItem

    Thank you for answer.

    Yes, it works perfectly. But still, it's a bit strange that setData() - method works only for text-data(in this case: strings, numbers etc.).

  5. #4
    Join Date
    Aug 2011
    Posts
    44
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows Symbian S60

    Default Re: QStandardItemModel and QStandardItem

    Just take a look at implementation of setIcon:
    Qt Code:
    1. inline void QStandardItem::setIcon(const QIcon &aicon)
    2. {
    3. setData(aicon, Qt::DecorationRole);
    4. }
    To copy to clipboard, switch view to plain text mode 
    It seems the role rules

  6. The following user says thank you to llev for this useful post:

    DmitryNik (9th October 2011)

  7. #5
    Join Date
    Sep 2011
    Posts
    45
    Thanks
    17
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QStandardItemModel and QStandardItem

    Now I got it. Thank you for answering!

  8. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QStandardItemModel and QStandardItem

    Quote Originally Posted by DmitryNik View Post
    Does QStandardItem class's method setData work only with primitive data, such strings, integers etc.? Does it depend on QVariant-class?
    It works with anything that can fit into QVariant. Since you can fit practically anything there, it works practically with anything.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 3
    Last Post: 29th October 2010, 23:26
  2. Tree without using of QStandardItem
    By NoRulez in forum Qt Programming
    Replies: 1
    Last Post: 12th July 2010, 12:23
  3. HTML and QStandardItem ?
    By alexandernst in forum Newbie
    Replies: 18
    Last Post: 4th August 2009, 12:07
  4. UTF8 and QStandardItem?
    By alexandernst in forum Newbie
    Replies: 17
    Last Post: 26th July 2009, 18:29
  5. QStandardItem question.
    By alexandernst in forum Qt Programming
    Replies: 6
    Last Post: 21st July 2009, 01:01

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.