我正在 Qt 中开发一个新项目,使用 QPainter 绘制 QWidget。问题是,当我尝试旋转 QPainter 时,我想绘制的文本会从 QWidget 中旋转出来。我知道如何解决这个问题,但不知何故,直到现在我才弄明白。我必须翻译我的 QPainter,以便将我的文本定位到正确的旋转位置,但我不知道如何指定该点到我应该翻译我的坐标系的位置。我没有翻译的代码:
QPainter painter;
float width = 40;
float height = 200;
float rangeMin = 0;
float rangeMax = 100;
float progress = 80;
QString format("%1/%2");
int alignmentHorizontal = Qt::AlignHCenter;
int alignmentVertical = Qt::AlignVCenter;
int fontSize = 12;
QColor backgroundColor = Qt::green;
QColor fontColor = Qt::black;
QFont font("Arial", fontSize);
QBrush backgroundBrush(backgroundColor);
QBrush transparentBrush(QColor(0,0,0,0));
QRect boundingRect = QRect(0, 0, width, height);
painter.begin(this);
painter.setFont(font);
painter.setPen(fontColor);
painter.drawRect(boundingRect);
float rectX = 0;
float rectY = …Run Code Online (Sandbox Code Playgroud)