• 3858阅读
  • 3回复

[提问]怎么给listView中的某行的字体设置单独的颜色 [复制链接]

上一主题 下一主题
离线wangyan23888
 

只看楼主 倒序阅读 楼主  发表于: 2013-08-31

    strList = ("a","b","c","d");
   int nCount;
    nCount = strList.length();
     for(int i = 0; i < nCount; i++)
     {
        QString string = static_cast<QString>(strList.at(i));
        QStandardItem *item = new QStandardItem(string);
        standardItemModel->appendRow(item);
     }
     ui->listView->setModel(standardItemModel);
listView中的c怎么显示红色,谢谢
离线bingyifeng

只看该作者 1楼 发表于: 2013-08-31
循环中设置前景色
if (string == "c") {
  item->setData(QBrush(QColor(255, 0, 0, 255)), Qt::ForegroundRole);
}

就可以了。
<span style="color:blue ">淘宝,绿石斋</span> <a href="http://shop33295817.taobao.com“> <span style="color:blue ">各种水晶饰品,手链,项链 </span></a>
离线wangyan23888

只看该作者 2楼 发表于: 2013-08-31
回 1楼(bingyifeng) 的帖子
谢谢
离线bingyifeng

只看该作者 3楼 发表于: 2013-08-31
不客气
<span style="color:blue ">淘宝,绿石斋</span> <a href="http://shop33295817.taobao.com“> <span style="color:blue ">各种水晶饰品,手链,项链 </span></a>
快速回复
限100 字节
 
上一个 下一个