[Qt-interest] setSceneRect vanished my items from GraphicsView :(

Enrico Ros enrico.qt at email.it
Sun Jul 12 10:27:51 CEST 2009


On Sunday 12 July 2009 08:32:55 Usman Ajmal wrote:
> Hi All,
>
> I having a problem with a GraphicsView widget. I am trying to display 50
> rectangles in the Graphics View widget but size of the rectangles are such
> that i need horizental scroll bars to view all the rectangles.
>
> My GraphicsView size is  (height, width) = (710, 530). When i set my scene
> rectangle to say 'setSceneRect(-20,-20,10,10)', i see some of my drawn
> rectangles. In order to view all rectangles i set the scene rectangle to
> (-360,-256,1000,530). I set 1000 so that i may get a horizental scroll bar.
>
> *Question:*
>
> I now, got the horizental scroll bar but i don't see 'any' of my rectangles
> at all. When i executed my program my rectangle just blinked and
> disappeared, leaving behind a white graphiceView plate of confusion.
>
> Any idea what i am missing here?

I tried this test code to simulate your behavior:
---------------------------
#include <QtGui>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QGraphicsView * gw = new QGraphicsView;
    gw->setFixedSize(710, 530);
    gw->show();

    QGraphicsScene * scene = new QGraphicsScene;
    gw->setScene(scene);
    gw->setSceneRect(-360,-256,1000,530);

    for (int i = 0; i < 50; i++)
        scene->addRect(qrand() % 200, qrand() % 200, 10 + qrand() % 500, 10 + 
qrand() % 500, QColor(qrand()%255, qrand()%255, qrand()%255));

    return a.exec();
}
---------------------------
and this works as expected! Analyze this and see if you can find something 
interesting. Also try to see if your items are deleted (place a breakpoint on 
destructor, for example) or if the scene is compromised by any later calls.

Enrico Ros



 
 
 --
 Caselle da 1GB, trasmetti allegati fino a 3GB e in piu' IMAP, POP3 e SMTP autenticato? GRATIS solo con Email.it http://www.email.it/f
 
 Sponsor:
 VOGLIA DI VACANZE?
* Vieni nei Riccione Family Hotels, gli alberghi specializzati per le vacanze dei bambini! Prenota online le nostre offerte
 Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=9303&d=12-7



More information about the Qt-interest-old mailing list