Start next text block below another text block in a QTextDocument



  • Hi,
    Currently I used a Qtextedit and separate text as blocks and gives different colors for each blocks, I use QTextblockFormat in QTextDocument. This display each block one by one, but I need parallel blocks, Following is my code,

    @QTextDocument* myDocument = new QTextDocument(ui->textedit);
    textedit->setDocument(myDocument);
    QTextCursor* myCursor = new QTextCursor(myDocument);

    QTextBlockFormat format;
    format.setNonBreakableLines(true);
    format.setBackground(Qt::green);
    format.setAlignment(Qt::AlignHCenter);
    
    myCursor->setBlockFormat(format);
    myCursor->insertText("Block1 ");
    
    
    format.setBackground(Qt::red);
    myCursor->insertBlock(format);
    myCursor->insertText("Block2 ");
    myCursor->insertHtml("<br>");
    myCursor->insertText("Block2");
    
    
    format.setBackground(Qt::yellow);
    myCursor->insertBlock(format);
    myCursor->insertText("Block3");@

Log in to reply
 

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