Home > Mobile >  QString after using Css code set colors, how to make this a QString in Qlistview or a QtableView dis
QString after using Css code set colors, how to make this a QString in Qlistview or a QtableView dis

Time:12-02

For example:
I created a QString, a code is as follows:
QString a;
A.a ppend (QString (" & lt; The font style='background - color: # FFCCCC; color:red; '& gt; The % 1 & lt;/font>" ). Arg (" aaa "));
The UI - & gt; TableView - & gt; SetShowGrid (false);
QStandardItemModel * model=new QStandardItemModel (1, 1);
The UI - & gt; TableView - & gt; SetModel (model);
The model - & gt; SetItem (0, 0, new QStandardItem (a));
That how to let him in Qtableview shows natural color, instead of showing the CSS code?
After the operation, display only a QString with CSS code instead of a colored QString,

CodePudding user response:

The default itemDelegate is not dealing with HTML, as plain text, according to you want to display HTML to write their own delegate

CodePudding user response:

Oh is so ah, bosses have the right link writing Delegate sent me under reference?

CodePudding user response:

Want to rewrite this change to display HTML amount is relatively large, I think if you just want to change the color of the item, a little bit more simple or don't have the HTML
Directly use QStandardItem: : setForeground and QStandardItem: : it is ok to setBackground
Of course, if you are interested in a custom item shows more or your own search itemDelegate related knowledge, is more complex
  •  Tags:  
  • Qt
  • Related