Draw polygon with image inside
Solved
General and Desktop
-
Hello,
I'd like to draw a polygon in a QGraphicsView. This works. Now I'd like to add a "background" image for the polygon.
A simple color like green works, but I'd like to use my own .png image.QVector<QPointF> hexPoints; hexPoints << QPointF(71,20) <<QPointF(35,0) <<QPointF(0,20) << QPointF(0,50) <<QPointF(35,71) <<QPointF(71,50); QPolygonF my_polygon(hexPoints); QImage *myImage = new QImage("my.png"); if(myImage->isNull()){ std::cout << "Could not read image!" << std::endl; } QBrush *myb = new QBrush(*myImage); QPen outlinePen(Qt::black); QGraphicsScene *scene = new QGraphicsScene(this); scene->addPolygon(my_polygon,outlinePen,*myb); ui->graphicsView->setScene(scene);
But sadly there is no image in my polygon.
How to fix it?
Thanks in advance!