PDA

View Full Version : How to embed unicode or utf8 symbols in a tooltip



ksierens
31st May 2013, 03:46
I am trying to set a tooltip that will contain the Mac command key symbol \u2318 but can not figure out how to do it.

ChrisW67
31st May 2013, 04:03
Putting the character in a QString, setting the tooltip, or making sure the font being used has the ⌘ glyph. Which bit is the problem?

The character is QChar(0x2318). There are a few ways to easily insert it.


#include <QApplication>
#include <QString>
#include <QLineEdit>

int main(int argc, char **argv)
{
QApplication app(argc, argv);
const QString text = QString("Test with %1 symbol").arg(QChar(0x2318));
// Or, if you can type it then chances are this will work
// const QString text = QString::fromUtf8("Test with ⌘ symbol");

QLineEdit l;
l.setText(text);
l.setToolTip(text);
l.show();
return app.exec();
}

ksierens
31st May 2013, 04:14
That was it! Thanks!