How to print text with QText2DEntity?



  • There was this question already:
    Re: Qt3D: how to print text? (QText2DEntity)
    And, as an only working example of usage, was this code:

    // camera position
    auto *camera = _view->camera();
    camera->setPosition({ 0, 40.0f, 0 });
    camera->setViewCenter({ 0, 0, 0 });
    camera->setUpVector({ 0, 0, 1.0f });
    camera->panAboutViewCenter(180.0f)
    // text
    auto *text2D = new Qt3DExtras::QText2DEntity(_rootEntity);
    text2D->setFont(QFont("monospace"));
    text2D->setHeight(20);
    text2D->setWidth(100);
    text2D->setText("monospace");
    text2D->setColor(Qt::yellow);
    auto *textTransform = new Qt3DCore::QTransform(text2D);
    textTransform->setRotation(QQuaternion::fromAxisAndAngle({ 1, 0, 0 }, 90.0f));
    textTransform->setScale(0.125f);
    text2D->addComponent(textTransform);
    

    But, it's not working for me: just nothing appears. Code looks correct, so, probably, the question is about correct parameters: width, height and scale for text. I've tried but didn't reach any result.

    Does anyone have any working example of this class usage?



  • Hi,

    do you have already a solution? Doesn't work for me neither.



  • @Cute3d, yes, it finally works. Idk what was wrong. Example project:https://github.com/Nonmant/Qt3DExtras-QText2DEntity-Example
    And due to god-knows-what reasons it doesn't work in debug mode. Hope, that project can help someone.


  • Banned

    This post is deleted!


Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.