问题描述
#include <QApplication>
#include <QGraphicspolygonItem>
#include <QGraphicsScene>
#include <QGraphicsView>
int main(int argc,char ** argv)
{
QApplication app(argc,argv);
QGraphicsScene scene;
QGraphicsView view;
view.resize(640,400);
view.setScene(&scene);
auto polygon = new QGraphicspolygonItem;
auto brush = QBrush(QColor(255,0));
polygon->setBrush(brush);
auto pen = QPen(brush,20);
pen.setCapStyle(Qt::RoundCap);
polygon->setPen(pen);
QpolygonF polygonPath;
polygonPath << QPointF{-50,-50};
polygonPath << QPointF{100,100};
polygonPath << QPointF{-50,100};
polygon->setpolygon(polygonPath);
scene.addItem(polygon);
view.show();
return app.exec();
}
尽管我设置了圆形帽,但多边形项目还是使用了直角帽。
解决方法
不确定,但是要获得使用多边形路径时要查找的结果,我认为实际上是需要设置的“连接”样式,而不是上限样式。所以改变...
pen.setCapStyle(Qt::RoundCap);
到...
pen.setJoinStyle(Qt::RoundJoin);