Qt-interest Archive, July 2007
QGraphicsScene and QGraphicsView disappearing
Message 1 in thread
Hello guys.
I'm stuck with those two objects in the subject. Say I have a QImage
set up by my code and say I have the following code to show it on a
QGraphicsView widget:
QImage out;
// Do things...
out.save(outFilename->text(), "png");
QGraphicsScene scene;
scene.setSceneRect(0, 0, width, height);
QGraphicsView view(&scene);
view.setBackgroundBrush(out);
view.resize(width, height);
view.show();
This is what I found browsing the docs and I'm not really sure it
works because when I issue the view.show() statement happens one of
these two:
1. Nothing is seen, nothing is said, the application just continues to run;
2. A very fast flash is seen on the screen which may be wide and tall
enough to be the QGraphicsView, nothing is said and the application
just continues to run.
What am I missing?
Thanks in advance
--
[ signature omitted ]
Message 2 in thread
On 17.07.07 10:20:11, Andrea Franceschini wrote:
> Hello guys.
> I'm stuck with those two objects in the subject. Say I have a QImage
> set up by my code and say I have the following code to show it on a
> QGraphicsView widget:
>
> QImage out;
> // Do things...
> out.save(outFilename->text(), "png");
> QGraphicsScene scene;
> scene.setSceneRect(0, 0, width, height);
> QGraphicsView view(&scene);
> view.setBackgroundBrush(out);
> view.resize(width, height);
> view.show();
>
> This is what I found browsing the docs and I'm not really sure it
> works because when I issue the view.show() statement happens one of
> these two:
>
> 1. Nothing is seen, nothing is said, the application just continues to run;
> 2. A very fast flash is seen on the screen which may be wide and tall
> enough to be the QGraphicsView, nothing is said and the application
> just continues to run.
>
> What am I missing?
Well, at the end of the function in which this code lives both the scene
and view are deleted because they are local variables. You have to
create them on the heap or make them class member variables to have them
live long enough to be shown. Of course if thats code in main.cpp it
should work.
Andreas
--
[ signature omitted ]
Message 3 in thread
2007/7/17, Andreas Pakulat <apaku@xxxxxx>:
> Well, at the end of the function in which this code lives both the scene
> and view are deleted because they are local variables. You have to
> create them on the heap or make them class member variables to have them
> live long enough to be shown. Of course if thats code in main.cpp it
> should work.
Yes, I was suspecting it was something like this. So, how am I
supposed to do this? Create the scene and the view as members of my
class (oh, yes, this code is inside a slot of a QMainWindow derived
class)? What if I wanted to use multiple pairs? QVectors of and QLists
of?
Thanks very much.
--
[ signature omitted ]
Message 4 in thread
On 17.07.07 10:56:51, Andrea Franceschini wrote:
> 2007/7/17, Andreas Pakulat <apaku@xxxxxx>:
>
> >Well, at the end of the function in which this code lives both the scene
> >and view are deleted because they are local variables. You have to
> >create them on the heap or make them class member variables to have them
> >live long enough to be shown. Of course if thats code in main.cpp it
> >should work.
>
> Yes, I was suspecting it was something like this. So, how am I
> supposed to do this? Create the scene and the view as members of my
> class (oh, yes, this code is inside a slot of a QMainWindow derived
> class)?
Yes.
> What if I wanted to use multiple pairs? QVectors of and QLists
> of?
Then have a vector or list member with pointers to the instances.
Andreas
--
[ signature omitted ]