Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QString degree symbol

I wonder what is the best and cleanest solution to write a degree symbol in a translation.

I had tr( "Snap to 90%1 angles" ).arg( QString::fromUtf8( "°" ) ) but this is not really nice.

I tried without success: tr( "Snap to 90° angles" )

I use this in a QAction: mCommonAngleAction = new QAction( tr( "Snap to 90° angles" ), menu );

Here is the result:

enter image description here

Do you have a good solution?

like image 472
Denis Rouzaud Avatar asked Sep 15 '25 14:09

Denis Rouzaud


1 Answers

The string you want to print depends quite a lot on where you want to print it. So where do you want to print Snap to 90° angles?

If you want to set a QLabel text to Snap to 90° angles a piece of code like label->setText(tr("Snap to 90° angles")); works just fine.

If you want to print it to console it depends on the console. If the console doesn't support UTF-8, unless you set a flag on that console to support UTF-8 characters, you're out of luck.

In a QMainWindow constructor, using the code

ui->menubar->actions().first()->setText(QObject::tr("Snap to 90° angless"));

generates:

enter image description here

like image 96
Iuliu Avatar answered Sep 18 '25 11:09

Iuliu