I'm trying to create an arrow item in Qt, so I'm basing myself on this example: http://doc.qt.io/qt-5/qtwidgets-graphicsview-diagramscene-arrow-cpp.html
The only difference being that I want to connect an arrow to one item and not two. And it is all working except when I try to drag my item, it leaves a blurry trail behind as if it was painting the whole drag movement and if I alt tab it disapears.
Only the arrow head is behaving like that, and I believe may be something wrong with its paint event:
void myArrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
qreal arrowSize = 20;
double angle = std::atan2(-line().dy(), line().dx());
QPointF arrowP1 = line().p1() + QPointF(sin(angle + M_PI / 3) * arrowSize,
cos(angle + M_PI / 3) * arrowSize);
QPointF arrowP2 = line().p1() + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize,
cos(angle + M_PI - M_PI / 3) * arrowSize);
arrowHead.clear();
arrowHead << line().p1() << arrowP1 << arrowP2;
painter->drawLine(line());
painter->drawPolygon(arrowHead);
}
If I take out the arrow head by removing this line painter->drawPolygon(arrowHead)
the line itself works fine.
Here is the whole source project: https://github.com/Matheusih/0000000123
Any hints, please?