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. About QTextEdit
Qt 6.11 is out! See what's new in the release blog

About QTextEdit

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 841 Views 1 Watching
  • 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.
  • T Offline
    T Offline
    TANG JI QIANG_CHINA_
    wrote on last edited by
    #1

    I have a problem, I insert a QTextObjectInterface object in QTextEdit control, I want to get the location of the object in the text, how to get its area.

    Besides, I want to insert an input region similar to QTextEdit in the rich text, and how to implement it.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      TANG JI QIANG_CHINA_
      wrote on last edited by
      #3

      @TANG-JI-QIANG_CHINA_ said in About QTextEdit:

      Besides, I want to insert an input region similar to QTextEdit in the rich text, and how to implement it.

      //register object
      QObject *fillBlankInterface = new HHFillIntheBlanks;
      fillBlankInterface->setParent(this);

      document->documentLayout()->registerHandler(FillBlankFormat, fillBlankInterface);
      

      // insert a object

      QTextCharFormat fillBlankCharFormat;
      fillBlankCharFormat.setProperty(FillBlankFormatId, id);
      fillBlankCharFormat.setProperty(FillBlankFormatValue, answer);
      fillBlankCharFormat.setObjectType(FillBlankFormat);

      QTextCursor cursor = textCursor();
      
      cursor.insertText(QString(QChar::ObjectReplacementCharacter), fillBlankCharFormat);
      

      setTextCursor(cursor);

      // object size
      QSizeF HHFillIntheBlanks::intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format)
      {
      QFontMetrics metriecs(format.toCharFormat().font());
      return QSizeF( metriecs.width(QStringLiteral("啊"))*10 , metriecs.capHeight());
      }

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi and welcome to devnet,

        How are you inserting your custom text object ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • T Offline
          T Offline
          TANG JI QIANG_CHINA_
          wrote on last edited by
          #3

          @TANG-JI-QIANG_CHINA_ said in About QTextEdit:

          Besides, I want to insert an input region similar to QTextEdit in the rich text, and how to implement it.

          //register object
          QObject *fillBlankInterface = new HHFillIntheBlanks;
          fillBlankInterface->setParent(this);

          document->documentLayout()->registerHandler(FillBlankFormat, fillBlankInterface);
          

          // insert a object

          QTextCharFormat fillBlankCharFormat;
          fillBlankCharFormat.setProperty(FillBlankFormatId, id);
          fillBlankCharFormat.setProperty(FillBlankFormatValue, answer);
          fillBlankCharFormat.setObjectType(FillBlankFormat);

          QTextCursor cursor = textCursor();
          
          cursor.insertText(QString(QChar::ObjectReplacementCharacter), fillBlankCharFormat);
          

          setTextCursor(cursor);

          // object size
          QSizeF HHFillIntheBlanks::intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format)
          {
          QFontMetrics metriecs(format.toCharFormat().font());
          return QSizeF( metriecs.width(QStringLiteral("啊"))*10 , metriecs.capHeight());
          }

          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