0

I have QGraphicsScene instance set to QGraphicsView on the GUI with scrollbars enabled and full view port update. But when I scroll my graphics view I get the items added to qgraphics scene disappeared on some point, though they are added in code correctly and are expected to be displayed upon scroll ( custom class inherited from QGraphicsItem ):

  class CSquare : public QObject, public QGraphicsItem

paint method is implemented as follows:

void CSquare::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    static int sz;
    painter->setFont(fnt_);
    painter->fillRect(this->r,this->br);
    painter->drawRect(this->r);
    //painter->drawText(this->p,this->txt);
    if (txt == "")
        return;
    if (fnt_.pixelSize()>0)
        sz = fnt_.pixelSize();
    else
        if (fnt_.pointSize()>0)
            sz = fnt_.pointSize();
        else
            if (fnt_.pointSizeF()>0)
                sz = fnt_.pointSizeF();

    switch (this->al_flag)
    {
    case 1:
        painter->drawText(this->p.x(),this->p.y(),sz*txt.size(),2*sz,Qt::AlignRight,this->txt);
        break;
    case 2:
        //painter->drawText(this->r,Qt::AlignLeft,this->txt);
        painter->drawText(this->p.x(),this->p.y(),sz*txt.size(),2*sz,Qt::AlignLeft,this->txt);
        break;
    case 3:
        //painter->drawText(this->r,Qt::AlignCenter,this->txt);
        painter->drawText(this->p.x(),this->p.y(),sz*txt.size(),2*sz,Qt::AlignCenter,this->txt);
        break;
    case 4:
        //painter->drawText(this->r,Qt::AlignJustify,this->txt);
        painter->drawText(this->p.x(),this->p.y(),sz*txt.size(),2*sz,Qt::AlignJustify,this->txt);
        break;
    }
}

One can see how they disappear on application run on this video screen cast:

https://www.box.com/s/h4h94×1avgay1crzvyzx

Can somebody hint what is the problem, how to resolve so the graphics items will not disappear on the view?

Thanks in advance.

1
  • That box.com link is broken Commented Feb 19, 2013 at 0:55

1 Answer 1

1

Yep, sorry. The problem is already solved: the problem was in custom function in the inherited class:

QRectF boundingRect() const;

That should return valid rectangle. Now I fixed that in my project and m going to remove the video.

Thank you for your attention.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.