Question

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.

Was it helpful?

Solution

Try with:

theta = QChar(0x98, 0x03);
alpha = QChar(0xb1, 0x03);

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top