About QTextEdit



  • 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.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    How are you inserting your custom text object ?



  • @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());
    }


Log in to reply
 

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