Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QListView add item text customization
Forum Updated to NodeBB v4.3 + New Features

QListView add item text customization

Scheduled Pinned Locked Moved Unsolved General and Desktop
qlistviewtext color
3 Posts 3 Posters 3.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kaluss
    wrote on last edited by
    #1

    Hi,
    does anybody know how to set text color for new added item into data model?
    My code looks like:

        myModel->insertRows(0, 1);
        QModelIndex index = myModel->index(0);
        this->m_logModel->setData(index, log); //this works fine !!!
    
        QBrush yellow;
        yellow.setColor(Qt::yellow);
        this->m_logModel->setData(index, yellow, Qt::TextColorRole); ///this not !!! text color is still black...
    

    Best regards,
    Tomek

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alex_malyu
      wrote on last edited by alex_malyu
      #2

      What is m_logModel, what is myModel?

      Your data model may or may not implement some roles.
      The QAbstractItemModel class implementation does nothing and returns false.
      It is a good idea to check what setData returns.

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by Chris Kawa
        #3

        First of all, as mentioned in the docs, Qt::TextColorRole is obsolete and you should not use it. Use Qt::ForegroundRole instead.
        Second, as mentioned by @alex_malyu, it depends on the model whether or not it implements that. QStandardItemModel for example will, but your custom model might not.
        So the question is what is your model class.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved