QPainter reset Transformation Does not work.
Unsolved
General and Desktop
-
Dear All,
I am having a QgraphicsItem on top of that I am drawing a text. Now I am rotating the graphics item but i don't want to rotate the text. So I am resetting the QPainter using reset transform method. But when I am applying the reset transform even my text is not painting by the painter.
I am giving the sample code.
I want to achieve that transformation should apply to graphics item but not on the text.painter->resetTransform(); qreal width = boundingRect().width(); qreal height = boundingRect().height(); QFont font = painter->font(); font.setFamily(QString("Courier New")); font.setBold(true); font.setPointSize(boundingRect().width()); painter->setFont(font); float widthFactor = boundingRect().width() / painter->fontMetrics().boundingRect(text).width(); float heightFactor = boundingRect().height() / painter->fontMetrics().boundingRect(text).height(); if(widthFactor > heightFactor) widthFactor = heightFactor; if((widthFactor < 1) || (widthFactor > 1.25)) { font.setPointSizeF(font.pointSizeF()*widthFactor); painter->setFont(font); } painter->drawText(boundingRect().x(), boundingRect().y(), width, height, Qt::AlignCenter,text);
TIA