Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to add text / label in Qt3D / Qt3DWindow

How to add text / label in Qt3D / Qt3DWindow

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.6k 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.
  • D Offline
    D Offline
    Dimis
    wrote on last edited by
    #1

    Hi all,

    I've a Qt3D window with some sphere meshes displayed.

    Is there any way to add some text labels on each of these spheres?

    Thank you in advance and have a good weekend!

    1 Reply Last reply
    0
    • H Offline
      H Offline
      HappyFeet
      wrote on last edited by
      #2

      Maybe this can help you: https://doc.qt.io/qt-5.10/qt3dextras-qtext2dentity.html

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dimis
        wrote on last edited by
        #3

        It's solved. For anyone interested below is my solution.

        void SceneModifier::addLabel(int label, float x, float y, float z)
        {
            QString s = QString::number(label);
                // Set label's text
               // auto *text = new Qt3DCore::QEntity(m_rootEntity);
            text = new Qt3DCore::QEntity();
            text->setParent(m_rootEntity);
        
                auto *textMaterial = new Qt3DExtras::QPhongMaterial(m_rootEntity);
                textMaterial->setDiffuse(QColor(0,100,0));
        
                auto *textTransform = new Qt3DCore::QTransform();
                textTransform->setTranslation(QVector3D(x, y, z));
                textTransform->setScale(2.5f);
        
                textMesh = new Qt3DExtras::QExtrudedTextMesh();
                textMesh->setText(s);
                textMesh->setDepth(.01f);
          }
        
        1 Reply Last reply
        2

        • Login

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