1

I'm a student programmer and I'm using Qt to create a Gui that gets input from users for a simulation. I am trying to use the theta and alpha symbol in a QLabel. I have looked over Qt's QLabel Documentation and found that QLabel does support Unicode. I tried using this unicode(U+0398)for my theta and this Unicode (U+03B1) for my alpha. The problem is I'm not to sure where this unicode should go in the ui. Qt doesn't say anything about it; so its either overlooked or something I should have already known. I tried to put it in the text field. That didn't work.

This is the latest code I tried:

QString alpha;
QString theta;
alpha.setUnicode(U+03B1);
theta.setUnicode(U+0398);
ui->labelExpansionAngle1->setText(alpha);
ui->labelExpansionAngle2->setText(alpha);
ui->labelOrientationAngle->setText(theta);

Then I tried:

ui->labelExpansionAngle1->setText("\u03B1");
ui->labelExpansionAngle2->setText("\u03B1");
ui->labelOrientationAngle->setText("\u0398");

I even tried using some of the other codes from the web pages I posted here. I was hoping that someone could shed some light on how this data needs to be put together. Thanks in advance for any help.

Wylie Coyote SG.
  • 1,009
  • 6
  • 22
  • 37
  • "I tried to put it in the text field." You'll have to include code so we know what you mean by this. – S.Lott Jan 09 '12 at 20:37

3 Answers3

5

Try with:

theta = QChar(0x98, 0x03);
alpha = QChar(0xb1, 0x03);
Frank Osterfeld
  • 24,815
  • 5
  • 58
  • 70
1

For those using PyQt5, you can directly set the unicode text to a QLabel through its constructor:

alpha_label = QLabel('\u03b1')

or setText:

alpha_label.setText('\u03b1')

If you need the unicode characters for any other greek letter have a look at:

https://unicode.org/charts/PDF/U0370.pdf

Pablo Guerrero
  • 936
  • 1
  • 12
  • 22
0

For those using QT on C++

QString alpha = QChar(0x03B1);
QString theta = QChar(0x03B8);

Use 0x followed by unicode character value. One can find all official unicode characters as mentioned @Pablo Guerrero in the above link