Results 1 to 4 of 4

Thread: need help on changing color of particular items in QStandardItemModel

  1. #1
    Join Date
    Sep 2009
    Posts
    54
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default need help on changing color of particular items in QStandardItemModel

    Dear friends,
    I need help on changing color of particular items in QStandardItemModel. i am displaying inbox messages in a standard item model. i need to differentiate readed messages and unreaded messages with different background color......


    thanks

    Regards,
    Askar

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: need help on changing color of particular items in QStandardItemModel

    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Sep 2009
    Posts
    54
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: need help on changing color of particular items in QStandardItemModel

    Thanks for your reply ,
    i tried but items background color is not changing,
    please let me know where doing wrong in the following code
    Qt Code:
    1. QDialog showdia = new QDialog;
    2. while(q1.next())
    3. {
    4. model->insertRow(MsgIDlist.size());
    5. for(int i=0;i<3;i++)
    6. {
    7. QStandardItem *item = new QStandardItem(q1.value(i).toString());
    8. QBrush b;
    9. b.setColor(Qt::gray);
    10. item->setBackground(b);
    11. model->setItem(MsgIDlist.size(),i,item);
    12. }
    13. }
    14. q1.clear();
    15. sourceView->setModel(model);
    16. sourceLayout = new QHBoxLayout;
    17. sourceLayout->addWidget(sourceView);
    18. sourceGroupBox->setLayout(sourceLayout);
    19. showdia->setFixedSize(300,220);
    20. showdia->show();
    To copy to clipboard, switch view to plain text mode 


    Regards
    Askar

  4. #4
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default Re: need help on changing color of particular items in QStandardItemModel

    Try something like the following:
    Qt Code:
    1. model->setData(model->index(row, column), Qt::blue, Qt::BackgroundRole);
    To copy to clipboard, switch view to plain text mode 

    Best Regards
    NoRulez

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

    Askar (25th November 2009)

Similar Threads

  1. Replies: 2
    Last Post: 24th August 2008, 14:42

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.