⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

Mouse problem in QGraphicsItem

  • Hello everyone.
    First of all I am new in qt and c++ graphics.
    I had to read a file and make a gui with that..
    For example i had the file
    rectangle 1 height 5.4 & some info
    rectangle 2 height 2.3 & some other info etc
    rectangle 3 height 6.2 & some other info etc

    To make them i call and overwritten class like the follow
    @class myNewClass : public QGraphicsItem
    myNewClass( MyData ); //where MyData is the height color etc info
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
    QWidget *widget);


    void mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent );

    I wanted when someone clicks on a rectangle to display a msg with some more info i have and i cant display..

    In the begin nothing works :( then i realized that QRectF boundingRect() const; must have the bounds where i want the mouse to be pressed for every item (correct me if i am wrong but it almost works)

    The problem is that if the rectangle is very large the mouse works only in a smaller area and not all over the rectangle. For example in the 2/3 of it. Also the redraw does not renew correctly in these area.

    NOTE : I display it with negative numbers for example the
    1st rect is from 0 to -height1
    2nd rect is from -sum_height to -height2

    i put this values in QRectF boundingRect() { return QRectF(my_values); }

    where myvalues is the read values i take from Mydata

    EDIT :
    When i put
    return QRectF(0,0, X,-7000) did not work
    return QRectF(0,-7000, X,7000) worked

Log in to reply