QGraphicsItem covered by mysterious white space



  • Hi guys.
    I need your help again! I have a problem drawing some items in a scene. This items are "attributes" composed of a circle and a text line next to it. The problem is, some of these attributes are covered by a mysterious white space when moving them to the right or bottom edge of a QGraphicsScene.
    The weird part is, this only happens when drawing these in a "Relationship" class, but it does not when doing so in a "Entity" class. Weirder still? The drawing is handled by the Attribute itself through a method "addToScene" (the attributes are not QGraphicsItem like the rest of the classes). This method is called by Entity or Relationship to draw them.
    Here is an image of the situation:
    Image link
    As you can see, the circles (which are also drawn by the Attribute class) are not covered, however the text is. I am asking because I find it extremely weird.
    Some example code:

    void RBinaryItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
    foreach(Attribute * att, rship->getAttributes()){
            att->addToScene(painter,x,y);
            y += 15;
        }
    }
    

    That is the paint method in Relationship class. The Entity class does the exact same usage.
    Thank you very much. Hope someone has an idea.


  • Qt Champions 2016

    Hello,
    It looks like some kind of clipping occurs, maybe compare the "attribute" objects' painting method, as it seems that the topmost circle (and text) are rendered properly?
    Additional code would be helpful, if you'd be willing to share it.

    Kind regards.



  • @kshegunov Well, here i show you the important part of the addToScene method in Attribute class.

    int Atttribute::addToScene(QPainter *painter, int x, int y){
    painter->drawText(QRectF(QPoint(x+30, y+5),QPointF(200, 200)), this->getName());
    painter->drawEllipse(x+20, y+9, 8, 8);
    }
    

    Hope this helps. Attribute class does not inherit QGraphicsItem, I received the code and will try, as long as I can, to keep it that way.
    Thanks!


  • Qt Champions 2016

    @danifujii
    Hello,
    Isn't QRectF(QPoint(x+30, y+5),QPointF(200, 200)) a bit suspicious? You set the top-left point relative to x and y, but put the bottom-right as fixed coordinates? Maybe try QPoint(x + 200, y + 200)? Aside from that it looks okay.



  • @kshegunov Right? I don't get why it would happen when used within a certain class and not with others.


  • Qt Champions 2016

    @danifujii
    I don't know, it does seem fine. Is it possible that something else (another item) is wanting to draw on top of this one and is erasing the background, although this seems far fetched?



  • @kshegunov I wouldn't think so as the only things that are added are the squares and rhombus items.

    SOLVED: It was what you said, the painting was wrong. It should have been x+200, y+200. That was code I received, that is why I didn't inspect it too much.
    Thank you!


  • Qt Champions 2016

    @danifujii
    You're welcome.
    Kind regards.


Log in to reply
 

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