Context Menu event with QGraphicsWidget
- by onurozcelik
In my application I subclass QGraphicsWidget
In paint I am drawing a line with pen width 4.
I reimplemented boundingRect() and shape().
But I can't catch context menu event every time I click right mouse button.
What is the problem.(Pen Width ? )
//Sample code for boundingRect() and shape()
QRectF boundingRect() const
{
qreal rectLeft = x1 < x2 ? x1 : x2;
qreal rectTop = y1 < y2 ? y1 : y2;
qreal rectWidth = (x1 - x2) != 0 ? abs(x1-x2) : 4;
qreal rectHeight = (y1 - y2) != 0 ? abs(y1 -y2) : 4;
return QRectF(rectLeft,rectTop,rectWidth,rectHeigt);
}
QPainterPath shape()
{
QPainterPath path;
path.addRect(boundingRect());
return path;
}