How to implement boundingRect and shape methods for a custom QGraphicLineItem item



  • Hi All,
    How to implement boundingRect and shape methods for a custom qgraphicline item, so that the item is easily selected when mouse is clicked on the item end points? Currently the custom line item is not receiving the mouse press events consistently. The mouse press is happening only randomly. I need to click on the line end points inorder to rotate and resize the line item.

    Please find my cureent implementation

    @
    QRectF CustomGraphicsLineItem::boundingRect()
    {
    return QGraphicsLineItem::boundingRect();
    }
    QPainterPath CustomGraphicsLineItem::shape()
    {
    //return QGraphicsLineItem::shape();
    const int adjustment = 5;
    QPainterPath path;
    QRectF rect = boundingRect();
    path.addRect(rect.adjusted(-adjustment, -adjustment, adjustment, adjustment));
    return path;

    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.