Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Synchronize same font looking between QML and c++
QtWS25 Last Chance

Synchronize same font looking between QML and c++

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 116 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mezmay
    wrote on last edited by
    #1

    Qt 5.15.8

    QML and c++ code use the same font.

    QML:

    TextEdit {  
            ...                  
            font: settings.font // font.preferShaping = false doesn't help
            ...
            renderType: Text.QtRendering // Text.NativeRendering also doesn't paint correctly
        }
    

    letters (corners are rounded):

    enter image description here

    C++:

    QSGNode* Text::updatePaintNode(QSGNode* oldNode, QQuickItem::UpdatePaintNodeData*)
    {
        ...
        QImage image(QSize(size, QImage::Format_ARGB32_Premultiplied);
        QPainter painter(&image);
        //painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); doesn't help also
        image.fill(QColor(0, 0, 0, 0));
        painter.setFont(settings.font());
        painter.drawText(rect, alignment, text));
        ...
    }
    

    letters (sharp corners):

    enter image description here

    How can I synchronize looking of the fonts between QML and c++ ?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved