#include #include #include #include #include #include #include #include #include class MyWidget : public QWidget { protected: virtual void paintEvent(QPaintEvent *event) override; public: MyWidget(QWidget *parent=nullptr) : QWidget(parent) { QWidget::setMinimumSize(400,400); } }; void MyWidget::paintEvent(QPaintEvent *event) { (void)event; // ignore QPainter painter(this); painter.setRenderHint(QPainter::TextAntialiasing,true); // small font // problem with "Noto Sans" font, no problem with "Arial" or "Tahoma" font QFont fnt(QStringLiteral("Noto Sans")); fnt.setPixelSize(20); // small // prefer full hinting fnt.setHintingPreference(QFont::PreferFullHinting); painter.setFont(fnt); // horizontal and vertical text const int contw = width(), conth = height(); painter.drawText(0,0,contw,conth,Qt::AlignHCenter|Qt::AlignBottom,QStringLiteral("il12345-+|#$%abcdefghy")); painter.setTransform(QTransform(0,-1, +1,0, 0,conth),false); painter.drawText(0,0,conth,contw,Qt::AlignHCenter|Qt::AlignVCenter,QStringLiteral("il12345-+|#$%abcdefghy")); } int main(int argc, char *argv[]) { // uncommenting either of the two lines below gives correct results //qputenv("QT_QPA_PLATFORM","windows:fontengine=freetype"); // looks good //qputenv("QT_QPA_PLATFORM","windows:fontengine=gdi"); // looks good // test was in Window 10 system with OS font scaling at 150% // if line below is commented out, the results still look bad, but less so. QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::RoundPreferFloor); // application QApplication app(argc,argv); // directory of "Noto Sans" font file // for testing, the font files is placed two directories up from the executable const QString appdir(QCoreApplication::applicationDirPath()), fontdir(QCoreApplication::applicationDirPath()+QStringLiteral("/../../")); if(QFontDatabase::addApplicationFont(fontdir+QStringLiteral("NotoSans-Regular.ttf"))==-1) { (void)QMessageBox::critical(nullptr,QStringLiteral("Error"),QStringLiteral("Could not open font file")); return 1; } // widget with texts MyWidget mywidget; mywidget.show(); return QApplication::exec(); }