
Originally Posted by
yartov
I have to adjust a Font size, when the user resized Widget where I draw text in a given rectangle.
Can somebody to give me a hint or point me to the right example?
Thanks in advance
You can draw a arial 6point to a 2000 pixel QWidget and is not need to change point size
only think Vector ...
QPainterPath is your friend ...
void ButtonAction::paintText()
{
p
->setRenderHint
(QPainter::Antialiasing);
const int borderI = 25;
/* button text */
textPath.addText(borderI,borderI * 2,fontText,textBut); //// fontText is any font() //// textBut text one line
/* fix view from text */
const QRectF reo
= textPath.
boundingRect();
TXTrect = reo;
/* tanslate text rect to rect window button */
p->setWindow ( reo.x() , reo.y() , reo.width() , reo.height() );
/* color text */
p->setPen(Qt::NoPen);
p->setBrush(colText);
p->drawPath(textPath);
Pm = p->deviceMatrix();
p->end();
}
void ButtonAction::paintText()
{
QPainter *p = new QPainter(this);
p->setRenderHint(QPainter::Antialiasing);
const int borderI = 25;
/* button text */
QPainterPath textPath;
textPath.addText(borderI,borderI * 2,fontText,textBut); //// fontText is any font() //// textBut text one line
/* fix view from text */
const QRectF reo = textPath.boundingRect();
TXTrect = reo;
/* tanslate text rect to rect window button */
p->setWindow ( reo.x() , reo.y() , reo.width() , reo.height() );
/* color text */
p->setPen(Qt::NoPen);
p->setBrush(colText);
p->drawPath(textPath);
Pm = p->deviceMatrix();
p->end();
}
To copy to clipboard, switch view to plain text mode
Bookmarks