Som
Som

Reputation: 195

Video not fitting in properly in QGraphicsView

I am trying a play a video(640 * 360) through rtsp in QGraphicsView. But the issue is that it is not fitting completely within the view and scroll bar is appearing, which should not happen. And moreover, I am able to get the same peace of code working properly in Linux environment but I am getting the issue in windows.

Please find the code snippet below, If anyone can point out the error I am making will be helpful.

    scene = new QGraphicsScene(this);
    view= new graphicsView();
    view->setScene(scene);
    videoItem = new QGraphicsVideoItem;
    player= new QMediaPlayer;
    player->setVideoOutput(videoItem);
    view->scene()->addItem(videoItem);
    controlLayout = new QHBoxLayout;
    controlLayout->setMargin(0);
    controlLayout->addWidget(view);
    view->setSceneRect(scene->sceneRect());
    view->scale(1.97,1.97);
    ui.m_pframePlay->setLayout(controlLayout);
    ui.m_pframePlay->show();
    player->setMedia(QUrl("rtsp:..."));
    player->play();

Upvotes: 0

Views: 505

Answers (1)

Omni
Omni

Reputation: 1022

The documentation for QGraphicsView sais about setSceneRect

The scene rectangle defines the extent of the scene, and in the view's case, this means the area of the scene that you can navigate using the scroll bars.

This means, setSceneRect does not resize the visible area of the view but only which area of the scene is visible in the view. So I guess you simply have to resize your view, e.g.

view->resize(scene->width()*1.97, scene->height()*1.97)

(I scaled width/height with 1.97 because you scale your view using factor 1.97 for some reason).

Upvotes: 2

Related Questions