Hi,
I made an error yesterday when drawing the text.I forgot the draw the text in the font bounding rect.
I had this, and it was working even when the text was too long. However this is incorrect since it isn't using the boundRectText.
painter->drawText(adjRect,Qt::AlignCenter|Qt::TextWordWrap,messageLabel);
painter->drawText(adjRect,Qt::AlignCenter|Qt::TextWordWrap,messageLabel);
To copy to clipboard, switch view to plain text mode
I changed the line to this and now the bounding rect expands whenever the text is expanded. It doesn't constrain to the adjRect.
painter->drawText(boundRectText,Qt::AlignCenter|Qt::TextWordWrap,messageLabel);
painter->drawText(boundRectText,Qt::AlignCenter|Qt::TextWordWrap,messageLabel);
To copy to clipboard, switch view to plain text mode
Here is my code.
QRectF adjRect
(rect
().
adjusted(txtRect.
x(),txtRect.
y(),
-txtRect.
x(),
-(rect
().
bottom() - (rect
().
y()+txtRect.
y()+txtRect.
height()))));
QRect boundRectText
(fm.
boundingRect(adjRect.
toRect(),Qt
::AlignCenter|Qt
::TextWordWrap,messageLabel
));
painter->drawText(boundRectText,Qt::AlignCenter|Qt::TextWordWrap,messageLabel);
painter->drawRect(adjRect); // debugging
painter->drawRect(boundRectText); // debugging
QFontMetrics fm(txtFont);
QRectF adjRect(rect().adjusted(txtRect.x(),txtRect.y(),-txtRect.x(), -(rect().bottom() - (rect().y()+txtRect.y()+txtRect.height()))));
QRect boundRectText(fm.boundingRect(adjRect.toRect(),Qt::AlignCenter|Qt::TextWordWrap,messageLabel));
painter->drawText(boundRectText,Qt::AlignCenter|Qt::TextWordWrap,messageLabel);
painter->drawRect(adjRect); // debugging
painter->drawRect(boundRectText); // debugging
To copy to clipboard, switch view to plain text mode
Here is a debug of the size of rectangles
QRect(2,127 473x40) = adjRect = good
QRect(-190,122 857x50) = boundRectText = bad. I expected this to be constrained to adjRect.
Is there something I am doing wrong?
Thanks
Bookmarks