Nominate our 2022 Qt Champions!

[Solved]QGraphicsScene | QGraphicsView

  • Hi:
    How can i see the whole scene into a qgraphicsview?
    I add a videowidget into a qgraphicsScene and i see a part of it.

    Help please.


  • did you do it like this?

    @ QGraphicsScene scene;
    scene.addText("Hello, world!");

    QGraphicsView view(&scene);;@

    normally your view will show your scene entirely.

  • you either decrease the size of scene to fit in to view ( QGraphicsScene::setSceneRect ) or increase size of view to show whole scene(QGraphicsView::setGeometry).


  • It didn't work.
    My basic code are:
    @media = new Phonon::MediaObject(this);
    video1 = new Phonon::VideoWidget();
    Phonon::createPath(media, video1);
    scene=new QGraphicsScene(this);

    I try with setSceneRect, setGeometry and the result it's the same! Also i try to setSceneRect with a QRect with a size more bit than the scene. Don't change anything.

    My problem is that:

    But, i want:

    Could i set any special property in QtDesigner?

  • Not sure setSceneRect or setGeometry is what you want to do. Have you tried fitInView()?

  • Yes, I try it. With it videowidget has a size about 40x40 pixeles. I see it too small into the center of the scene.
    I think that any inherit size is missing or bad between proxywidget and qgraphicsscene. Or the proxywidget don't handle any signal or event.

    If you want to see my code. See

  • Had a quick look at your code.
    Cannot see why ui->view->fitInView(proxy,Qt::KeepAspectRatioByExpanding) should not do what you want. Just curious - why are you resizing video1 to half its size? And you could add some more debug output showing the bounding rect of proxy, for example.
    Also, from your pictures, it is a bit unclear why you need the graphicsview at all. Are you planning to add other things to it than just the video widget?
    Apart from that, I'm not sure I can be of more help, sorry.

  • I need to show some text above the videowidget(it's a videosubtitle software). If i can do this in a easy way, i want to know it.
    Thanks Ludde.

  • To just add subtitles, I would probably create a subclass of Phonon::VideoWidget, override its paintEvent(), and draw the text using QPainter::drawText() after letting the VideoWidget draw the video. Have never used the Phonon classes, though, but cannot see why it would not work.

  • Now it's working properly. I reimplement the resizeEvent of the Widget with view->fitinview(proxy,Qt:keepaspectratio). But at start the videowidget it's too small. When i resize the window it takes properly size. Any idea?

  • The only thing I can think of is that the videowidget might not get its size until after you've put it in the scene.

    But I still cannot see why you want to use QGraphicsView for this. You can do your own painting on/in any widget. QGraphicsView is great for keeping track of large numbers of individual grahpical items, but does not really help you that much if you just want to put text on top of a video.

Log in to reply