Important: Please read the Qt Code of Conduct -

QTextDocument: overlay multiple items on the same cursor position

  • I'm trying to print the "usual" form for date and signature, something like this:

    Signature            Date
    ______________       _______________

    but on the signature's line I want to print a QImage (the signature).
    I tried the following:

    QTextCharFormat charFormat;
    QTextTableFormat tableFormat;
    tableFormat.setWidth(QTextLength(QTextLength::PercentageLength, 100));
    textTable = cursor.insertTable(2, 2, tableFormat);
    textTable->cellAt(0, 0).firstCursorPosition().insertText(tr("Signature"), charFormat);
    textTable->cellAt(0, 1).firstCursorPosition().insertText(tr("Date"), charFormat);
    textTable->cellAt(1, 0).firstCursorPosition().insertText("_________________________", charFormat);
    textTable->cellAt(1, 0).firstCursorPosition().insertImage(myQImage);
    textTable->cellAt(1, 1).firstCursorPosition().insertText("_________________________", charFormat);

    but calling the firstCursorPosition() twice it just makes room for the image:

    Signature            Date
    image goes here      _______________

    Instead I want the image is printed over the line. Because it's a png I also expect the alpha channel is honored and I can see the line behind.

    How to achieve this?

Log in to reply