QTextDocument layout problem with text disappears
Hi,
I am making a text editor using QGraphicTextItem and QTextDocument clases and I have a problem with text that disappears.
I have inserted my custom item at the begining of the block:
I use my CharFormat for the item:
Code:
...
MyItemFormat myItemFormat(format, listId(), level);
cursor
->insertText
(QString(QChar::ObjectReplacementCharacter), myItemFormat
);
...
Then I have registered handler class:
Code:
MyHandler* mh = new MyHandler(this);
document()->documentLayout()->registerHandler( MyItemFormat::Type, mh);
I have reimplemented intristicSize and drawObject methods:
and a draw
Code:
{
....
QBrush charBrush
= charFormat.
foreground();
QFont font
(charFormat.
font());
QColor charColor
= charBrush.
color();
painter->setFont(font);
painter->setPen(charColor);
qDebug() << rect << " ; " << painter->pen() << " ; " << painter->font();
painter->drawText(rect, Qt::AlignBottom, imageText);
rect1.translate(-30, 0); // move new rect a little bit to the left to draw on left margin
imageText = "B";
qDebug() << rect1 << " ; " << painter->pen() << " ; " << painter->font();
painter->drawText(rect1, Qt::AlignBottom, imageText);
}
And this works fine. AA is drawn on start of text block and B is drawn on left margin.
But, when I select some text in the text block AA is still visible, but B disappears.
Debug print is not changed when text in block is selected (still show correct rect size and position, and pen and font colors) but text B is not visible.
Any idea??? I sopose that drawObject is not intended for drawing outsidee the QTextBlock rectangle or something like that but I am sure that there is a way to override this problem, just I do not see it.
Re: QTextDocument layout problem with text disappears
No idea why text is not visible???
At least, I would like to understand what happend, eaven if there is no solution.