10

My QLabels look quite ugly, it seems that there's no anti-aliasing. How can I enable this feature (assuming it's available)?

laurent
  • 88,262
  • 77
  • 290
  • 428
  • 1
    This is a very wild guess since I don't have experience with Qt, but does setting a background color solve the problem ? Many UI systems don't do font anti-aliasing without a background since the aliased pixels depend on a background color to blend in to. – DarkDust Jul 19 '11 at 11:20
  • You probably should tell what OS you are using. My QLabels look just fine. –  Jul 19 '11 at 11:29
  • Are you using Qt software rendering (raster) ? – Thomas Vincent Jul 19 '11 at 13:49

2 Answers2

15
QLabel * l = new QLabel();
QFont f=l->font();
f.setStyleStrategy(QFont::PreferAntialias);
l->setFont(f);

you may also alter application font settings, to be applied to all widgets you use...

QFont f=QApplication::font();
f.setStyleStrategy(QFont::PreferAntialias);
QApplication::setFont(f);
nonot1
  • 2,788
  • 4
  • 25
  • 41
Raiv
  • 5,731
  • 1
  • 33
  • 51
2

You can set the Antialisasing attribute in the label's font to PreferAntialias. You can do it in QtCreator or by code like this :

QFont f("Times", 50);
f.setStyleStrategy(QFont::PreferAntialias);
ui->label->setFont(f);

Hope this helps

Yassine Zaroui
  • 403
  • 3
  • 14