我正在尝试在 qgraphicswidget 中绘制文本。场景的水平比例为 -180 到 180,垂直比例为 -90 到 +90(这是一张世界地图)。
当我放大地图上的单个项目时,我希望显示一些文本。我的一个特定项目的绘制功能的代码如下所示:
void AirportGraphicsWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
QPen pen;
pen.setStyle(Qt::PenStyle::NoPen);
painter->setBrush(Qt::lightGray);
painter->setPen(pen);
if (m_curr_lod <= LevelOfDetail::MEDIUM) {
painter->setBrush(QColor(206, 211, 219));
painter->drawEllipse(m_airport_significance_rect);
} else if(m_curr_lod == LevelOfDetail::HIGH) {
painter->setBrush(QColor(56, 55, 52, 150));
painter->drawEllipse(m_airport_boundary);
DrawRunways(painter, option, widget);
} else {
painter->setBrush(QColor(56, 55, 52));
painter->drawEllipse(m_airport_boundary);
pen.setStyle(Qt::PenStyle::SolidLine);
pen.setColor(Qt::black);
painter->setPen(pen);
DrawRunways(painter, option, widget);
DrawILS(painter, option, widget);
DrawCOM(painter, option, widget);
QPen pen;
pen.setStyle(Qt::PenStyle::SolidLine);
pen.setColor(Qt::white);
pen.setWidth(0);
QFont font("Arial");
font.setPixelSize(15);
painter->setFont(font);
painter->setPen(pen);
painter->drawText(m_airport_boundary, "TEST");
}
}
drawText 调用似乎根本不起作用。我在这个缩放级别的比例非常小。m_airport_boundary QRectF 变量具有以下值: { x = -0.010286252057250001, y = -0.010286252057250001, width = 0.020572504114500002, height = 0.020572504114500002 }
m_airport_boundary 矩形的绘图是可见的,所以我知道我试图在正确的位置绘图。谁能告诉我我做错了什么?
正在绘制的屏幕截图... 黑圈是 m_airport_boundary 椭圆。绿色的东西是 DrawILS 的结果,蓝色的圆圈是 DrawCOM