Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.9.1
-
None
Description
I Have a QGraphicsWidget which draws some text on a QGraphicsScene. In the Paint Method I'm using a QTextDocument and QTextLayout to format an draw the text. The strange thing that I've noticed is that the Cursor (QTextLayout::drawCursor) is not drawn when there is no background painted. As soon as I draw a background (with the same Painter), the cursor is drawn, without the background, no cursor visible.
void AnnotationText::paint(QPainter *painter, const QStyleOptionGraphicsItem *style, QWidget *widget) { // Paint border AbstractAnnotationRect::paint(painter, style, widget); auto textArea = mRect->normalized(); if (mIsInEditMode) { setupEditModeOutlinePen(); painter->setPen(mEditModeOutlinePen); painter->drawRect(textArea); } // Paint text painter->setPen(properties()->textColor()); auto margin = properties()->width(); painter->setClipRect(boundingRect().adjusted(margin, margin, -margin, -margin)); QFontMetrics fontMetrics(textProperties()->font()); auto boxHeight = 0; QTextDocument document(mText); for (auto block = document.begin(); block != document.end(); block = block.next()) { auto blockPosition = block.position(); auto blockLength = block.length(); QTextLayout textLayout(block); textLayout.setFont(textProperties()->font()); auto blockHeight = 0; textLayout.setCacheEnabled(true); textLayout.beginLayout(); while (true) { auto line = textLayout.createLine(); if (!line.isValid()) { break; } line.setLineWidth(textArea.width() - margin * 2); blockHeight += fontMetrics.leading(); line.setPosition(textArea.adjusted(margin, margin, 0, 0).topLeft()); blockHeight += line.height(); } textLayout.endLayout(); textLayout.draw(painter, QPoint(0, boxHeight)); painter->setBrush(Qt::NoBrush); painter->drawRect(textArea); if (mTextCursor.isVisible() && (mTextCursor.position() >= blockPosition && mTextCursor.position() < blockPosition + blockLength)) { textLayout.drawCursor(painter, QPointF(0, boxHeight), mTextCursor.position() - blockPosition, 1); } boxHeight += blockHeight; } }
Same code build via CI with Qt Verion 5.6.1 works fine, on my PC build as AppImage and on another machine which runs on Windows.
Attachments
Issue Links
- relates to
-
QTBUG-85955 TextArea and ScrollView, not show cursor at end of line.
- Closed