superscript for QTableWidget header

浪尽此生 提交于 2019-12-07 11:16:23

Try QString("Area \n [m%1]").arg(QChar(0x00B2)) or QString("Area \n [%1]").arg(QChar(0x33A1)). It should work with any source encoding.

If it doesn't work, maybe your font doesn't support this symbols to display. If there is no other way you may try to imitate headers by QLabel with HTML like this: "<B> Area <BR> [m<SUP>2</SUP>] </B>". Remember that setting QWidgets to QTableWidget is usually ugly and possibly slow. And you will have bad architecture.

Try :

ui.tableWidget->horizontalHeaderItem(2)->setText(QString::fromUtf8("Area \n [m\u00B2]"));

after searching I found a solution for this, I am not good enough to know why it works but it works fine for me

const char s[] = {
    0x6D,               // m
    0xC2, 0xB2,         // superscript two
    0x00                // NUL terminator
};
QString str = QString::fromUtf8(s);

and then

ui.tableWidget->horizontalHeaderItem(2)->setText("Area \n [m" + str + "]");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!