QTableWidget 标题的上标 [英] superscript for QTableWidget header

查看:74
本文介绍了QTableWidget 标题的上标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习QT,不得不设计一个这样的表格

I'm learning QT and have to design a table like this

我需要用2"作为上标的m2".

I need "m2" with "2" as superscript.

这是我的代码:

ui.tableWidget->horizontalHeaderItem(0)->setText("Date");
ui.tableWidget->horizontalHeaderItem(0)->setBackgroundColor(QColor(217, 217, 217));
ui.tableWidget->horizontalHeaderItem(1)->setText("House address");
ui.tableWidget->horizontalHeaderItem(1)->setBackgroundColor(QColor(217, 217, 217));
ui.tableWidget->horizontalHeaderItem(2)->setText("Area \n [m\u00B2]");
ui.tableWidget->horizontalHeaderItem(2)->setBackgroundColor(QColor(217, 217, 217));
ui.tableWidget->horizontalHeaderItem(3)->setText("Price \n [USD]");
ui.tableWidget->horizontalHeaderItem(3)->setBackgroundColor(QColor(217, 217, 217));
ui.tableWidget->horizontalHeaderItem(4)->setText("Price/Area \n [USD/m\u00B2]");
ui.tableWidget->horizontalHeaderItem(4)->setBackgroundColor(QColor(217, 217, 217));

我使用\u00B2"作为2"作为上标,但它不起作用,背景颜色也没有改变.请帮帮我,非常感谢!

I used "\u00B2" for "2" as superscript but it doesn't work, the background color also does not change. Please help me, many thanks !

推荐答案

尝试 QString("Area \n [m%1]").arg(QChar(0x00B2))QString("区域\n [%1]").arg(QChar(0x33A1)).它应该适用于任何源编码.

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

如果不行,可能你的字体不支持这个符号显示.如果没有其他方法,您可以尝试通过 QLabel 使用 HTML 模拟标题,如下所示: " Area
[m2] </B>".请记住,将 QWidgets 设置为 QTableWidget 通常很难看并且可能很慢.而且你的架构会很糟糕.

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.

这篇关于QTableWidget 标题的上标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆