¶ 设置字体
QFont nullFont;
true);
nullFont.setItalic(true); nullFont.setBold(
这里设置了斜体(italic)和粗体(bold),字体型号为默认。
¶ 设置颜色
QBrush nullColor(Qt::gray)
这里设置成灰色。如果想要其他颜色可以查一下QBrush
的帮助。
¶ 应用到QTableWidgetItem上
QTableWidgetItem *item = new QTableWidgetItem("NULL");
item->setFont(nullFont); item->setBackground(nullColor);
这里使用了setBackground
,也就是把nullColor
设置为QTableWidgetItem的背景色。如果要设置文字颜色(也就是前景色),使用setForeground
效果: