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. Unable to display text property on screen
Qt 6.11 is out! See what's new in the release blog

Unable to display text property on screen

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 3 Posters 1.1k 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.
  • J Offline
    J Offline
    Jaekook Choi
    wrote on last edited by Jaekook Choi
    #1

    76D21C3D-42C4-43FB-A999-A4942401A4F8.jpeg

    Hi. I have a problem.
    I think there is something wrong. It is not printing properly on the screen.
    I made it print from QML.
    Sometimes it works properly and sometimes it works like the picture above
    What should i do.

    jsulmJ 1 Reply Last reply
    0
    • J Offline
      J Offline
      Jaekook Choi
      wrote on last edited by
      #6

      The problem has been successfully resolved.

      But I don't know why this problem is resolved.

      Problem was "font.bold "

      I wrote "true" on almost every "font.bold".

      So, I only left a few, and I fixed most of them to "false."

      it operated well.

      1 Reply Last reply
      0
      • J Jaekook Choi

        76D21C3D-42C4-43FB-A999-A4942401A4F8.jpeg

        Hi. I have a problem.
        I think there is something wrong. It is not printing properly on the screen.
        I made it print from QML.
        Sometimes it works properly and sometimes it works like the picture above
        What should i do.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @Jaekook-Choi said in Unable to display text property on screen:

        What should i do

        Provide more information.
        On which platform?
        On what hardware?
        Which Qt version?
        What font?
        What are you using to print text?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        J 1 Reply Last reply
        0
        • jsulmJ jsulm

          @Jaekook-Choi said in Unable to display text property on screen:

          What should i do

          Provide more information.
          On which platform?
          On what hardware?
          Which Qt version?
          What font?
          What are you using to print text?

          J Offline
          J Offline
          Jaekook Choi
          wrote on last edited by
          #3

          @jsulm

          I'm sorry

          vxworks7
          intel 8th
          based on Qt 6.2.3
          NanumGothic.ttf
          through invokeMethod

          in CPP
          QMetaObject::invokeMethod(m_pOperPPIQmlInstance, "show_c2a_key", Q_ARG(QVariant, indi));

          in QML
          function show_c2a_key(indi)
          {
          if(indi === 1) {
          c2a_key.text = "ABCDEFGHI"
          }
          }

          and

          Text{
          id: c2a_key
          x: 544
          y: 430
          color: "green"
          text: ""
          font.pixelSize: 16
          font.bold: true
          font.preferShaping: false
          }

          When the program runs, the terminal outputs the following statement:

          QFontDatabase: Cannot find font directory /usr/local/Qt-5.15.3/lib/fonts.
          Note that Qt no longer ships fonts. Deploy some (from https://dejavu-fonts.github.io/ for example) or switch to fontconfig.

          Is there any connection?

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lemons
            wrote on last edited by
            #4

            can't you ship the font with your application?

            // main.cpp
            // register shipped font to application
            QFontDatabase::addApplicationFont(":/your/qrc/path/NanumGothic.ttf");
            

            You can also add the font from QML:

            // qmldir
            singleton Fonts 1.0 Fonts.qml
            
            // Fonts.qml
            pragma Singleton
            import QtQuick 2.12
            
            Item {
                property FontLoader nanumGothic: FontLoader {
                    source: "qrc:/your/qrc/path/NanumGothic.ttf"
                }
                readonly property string indiFont: nanumGothic.name
            }
            
            
            // in any other QML
            Text{
                text: "ABCDEF"
                font.family: Fonts.indiFont
            }
            
            J 1 Reply Last reply
            0
            • L lemons

              can't you ship the font with your application?

              // main.cpp
              // register shipped font to application
              QFontDatabase::addApplicationFont(":/your/qrc/path/NanumGothic.ttf");
              

              You can also add the font from QML:

              // qmldir
              singleton Fonts 1.0 Fonts.qml
              
              // Fonts.qml
              pragma Singleton
              import QtQuick 2.12
              
              Item {
                  property FontLoader nanumGothic: FontLoader {
                      source: "qrc:/your/qrc/path/NanumGothic.ttf"
                  }
                  readonly property string indiFont: nanumGothic.name
              }
              
              
              // in any other QML
              Text{
                  text: "ABCDEF"
                  font.family: Fonts.indiFont
              }
              
              J Offline
              J Offline
              Jaekook Choi
              wrote on last edited by
              #5

              @lemons

              Sorry for late reply

              first.

              int main(int argc, char *argv[])
              {
              #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
              QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
              #endif
              QGuiApplication app(argc, argv);

              QSurfaceFormat format;
              format.setSamples(8);
              QSurfaceFormat::setDefaultFormat(format);
              
              int fontID = QFontDatabase::addApplicationFont(":/font/NanumGothic.ttf");
              qDebug() << "Font ID : " << fontID << QFontDatabase::applicationFontFamilies(fontID);
              
              QFont defaultFont;
              
              defaultFont.setFamily("NanumGothic");
              defaultFont.setPixelSize(20);
              defaultFont.setStyleStrategy(static_cast<QFont::StyleStrategy>(defaultFont.styleStrategy() | QFont::PreferNoShaping));
              app.setFont(defaultFont);
              
              CEventFilter cEF;
              app.installEventFilter(&cEF);
              
              CAppContainer appContainer;
              appContainer.initialize();
              
              appContainer.show();
              
              return app.exec();
              

              }

              This is my main function.

              you told me to write "QFontDatabase::addApplicationFont(":/your/qrc/path/NanumGothic.ttf");"

              But I've already written it.

              By any chance, is there a strange part of my main function?

              If I made the character print from c++, it would be printed without any problem, but if I made the character print from QML, the above problem occurred.

              So I think the font is applied to c++, but the font is not applied to QML.

              But If i erase code related to the font in c++, QML totally doesn't print character.

              So the font is not applied?

              And

              Now I'm trying to second way that you said(Appliying fonts in QML)

              Do i have to make a qmldir file and put one sentence that "singleton Fonts 1.0 Fonts.qml"?

              Thank for read my reply :)

              1 Reply Last reply
              0
              • J Offline
                J Offline
                Jaekook Choi
                wrote on last edited by
                #6

                The problem has been successfully resolved.

                But I don't know why this problem is resolved.

                Problem was "font.bold "

                I wrote "true" on almost every "font.bold".

                So, I only left a few, and I fixed most of them to "false."

                it operated well.

                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