c++ – What is object index of QTextFormat? – Education Career Blog

The function int QTextFormat::objectIndex () const returnes an object index. What is it? And what if I do the following:

    QTextBlockFormat bfmt;
    bfmt.setObjectIndex(0);

What this code does?

ADDED:
Here there is a function void TextEdit::textStyle(int styleIndex). This function is for adding a list into QTextEdit, or making it a normal (standard text). In the function mentioned above there is a code snippet like this:

 } else {
     // ####
     QTextBlockFormat bfmt;
     bfmt.setObjectIndex(-1);
     cursor.mergeBlockFormat(bfmt);
 }

This code snippet is in order to make list a standard text. But it does not work and only works when I write

    QTextBlockFormat bfmt;
    bfmt.setObjectIndex(0);
    m_textCursor.mergeBlockFormat(bfmt);
    m_textEdit->setTextCursor(m_textCursor);

Please explain me why?

,

QTextOjbects are used to group parts of a QTextDocument. Some text objects would be QTextList, QTextFrame, QTextTable etc. Each of these text objects have an index. The ojbectIndex of a QTextFormat associates the format object with a text object.

Your code above would associate bfmt with the text object with index 0.

Leave a Comment