2016-03-03 30 views

回答

0

您應該使用supHTML標記以擁有超級腳本。所以mm<sup>3</sup>在支持豐富文本的小部件中會產生超級腳本。

在這裏您應該有一個自定義委託來顯示特定列的富文本。只需創建一個自定義QStyledItemDelegate。這可能是這樣的:

class RichTextDelegate: public QStyledItemDelegate 
{ 
public: 
    RichTextDelegate(QObject *parent = 0); 

    void paint(QPainter *painter, 
          const QStyleOptionViewItem &option, 
          const QModelIndex &index) const; 
}; 

RichTextDelegate::RichTextDelegate(QObject *parent):QStyledItemDelegate(parent) 
{ 
} 

void RichTextDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const 
{ 

    if(option.state & QStyle::State_Selected) 
     painter->fillRect(option.rect, option.palette.highlight()); 


    painter->save(); 

    QTextDocument document; 
    document.setTextWidth(option.rect.width()); 
    QVariant value = index.data(Qt::DisplayRole); 
    if (value.isValid() && !value.isNull()) 
    { 
       document.setHtml(value.toString()); 
       painter->translate(option.rect.topLeft()); 
       document.drawContents(painter); 

    } 

    painter->restore(); 
} 

你應該爲特定的列設置項目委託:如果你設置成一排mm<sup>3</sup>具體列示範文本

​​

現在,這將是正常顯示:

model->item(rowIndex, colIndex)->setText(mm<sup>3</sup>); 
0

對於呈現出標的特定情況下「3」,另一種選擇是使用相應的Unicode符號 - Qt的文本渲染應該找到一個合適的字形無論是你的主字體還是後備字體。然而,這比上面的答案要少得多 - 它只適用於各種通常定義的上標。