text in paintevent
-
Hi,

I have overlay text, aligned , can i have the overlay text aligned one by one vertically in paintevent.
painter.drawText(rect,Qt::AlignBottom | Qt::AlignLeft,StartString); painter.drawText(rect,Qt::AlignBottom | Qt::AlignCenter,Centerstring); painter.drawText(rect,Qt::AlignBottom | Qt::AlignRight,EndString);Thanks,
-
Hi,

I have overlay text, aligned , can i have the overlay text aligned one by one vertically in paintevent.
painter.drawText(rect,Qt::AlignBottom | Qt::AlignLeft,StartString); painter.drawText(rect,Qt::AlignBottom | Qt::AlignCenter,Centerstring); painter.drawText(rect,Qt::AlignBottom | Qt::AlignRight,EndString);Thanks,
hi,
seems like if you add a new line
\nQPainter actually draws a new line. Take a look at the docu hereIn case you want to use multiple drawTexts, you'll have to add an Vertical offset to the
rect, of at least the average Char height, instead of a horizontal offset but that seems kind of obvious!? -
I used \n , but u specified vertical offset , how can i achieve ,?.
Thanks,
-
I used \n , but u specified vertical offset , how can i achieve ,?.
Thanks,
QFontMetrics metrix(painter->font()); int hOffset = metrix.height(); painter.drawText(rect,Qt::AlignBottom | Qt::AlignLeft,StartString); rect = rect.setY(rect.y()+hOffset); painter.drawText(rect,Qt::AlignBottom | Qt::AlignCenter,Centerstring); rect = rect.setY(rect.y()+hOffset); painter.drawText(rect,Qt::AlignBottom | Qt::AlignRight,EndString); -
Hi,

I have overlay text, aligned , can i have the overlay text aligned one by one vertically in paintevent.
painter.drawText(rect,Qt::AlignBottom | Qt::AlignLeft,StartString); painter.drawText(rect,Qt::AlignBottom | Qt::AlignCenter,Centerstring); painter.drawText(rect,Qt::AlignBottom | Qt::AlignRight,EndString);Thanks,
@Pradeep-Kumar I'm not sure I understand your question. But isn't Qt::AlignVCenter what you're looking for?
-
Hi @Pradeep-Kumar ,
Try This,
QRect firstTextrect(0,0,rect.width(),rect.heght()/3);
QRect secTextrect(0,firstTextrect.bottomLeft(),rect.width(),rect.heght()/3);
QRect ThirdTextrect(0,secTextrect.bottomLeft(),rect.width(),rect.heght()/3);painter.drawText(firstTextrect,Qt::AlignLeft,StartString);
painter.drawText(secTextrectr,Qt::AlignLeft,Centerstring);
painter.drawText(ThirdTextrect,Qt::AlignLeft,EndString);