【问题标题】:How to draw filled polygon on QGraphicsScene如何在 QGraphicsScene 上绘制填充多边形
【发布时间】:2017-04-16 02:08:22
【问题描述】:

我想在 QGraphicsScene 上绘制一个填充了特定颜色的多边形。然后我使用以下代码:

QPolygonF poly;
poly << QPointF(10, 10) << QPointF(10, 50) << QPointF(30, 70 )<< QPointF(60, 50) << QPointF(50, 10);
QBrush brush;
brush.setColor(Qt::red);
QPen pen(Qt::green);
QGraphicsScene graphics_scene_ = new QGraphicsScene(0,0,200,200);
graphics_scene_->addPolygon(poly, pen, brush);
setScene(graphics_scene_);

但是我只得到一个带有绿色边框的空心多边形,但多边形内没有红色填充。 我该如何解决?

【问题讨论】:

    标签: c++ qt qt5 qgraphicsscene qcolor


    【解决方案1】:

    QBrush() 缺少样式。你应该使用:

    QBrush brush
    brush.setColor(Qt::red);
    brush.setStyle(Qt::SolidPattern);
    

    或者最好这样,因为Qt::SolidPattern 样式默认出现:

    QBrush brush(Qt::red);
    

    【讨论】:

      猜你喜欢
      • 2011-01-04
      • 1970-01-01
      • 2011-04-21
      • 2020-03-20
      • 2015-01-12
      • 1970-01-01
      • 2011-11-29
      • 1970-01-01
      相关资源
      最近更新 更多