视频不适合 QGraphicsView

Video not fitting in properly in QGraphicsView

我正在尝试在 QGraphicsView 中通过 rtsp 播放视频 (640 * 360)。但问题是它没有完全适合视图并且出现了滚动条,这是不应该发生的。此外,我能够在 Linux 环境中正常运行相同的代码,但我在 windows 中遇到了问题。

请找到下面的代码片段,如果有人能指出我所犯的错误将会有所帮助。

    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();

QGraphicsView 的文档是关于 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.

这意味着,setSceneRect 不会调整视图可见区域的大小,只会调整视图中可见的场景区域。所以我猜你只需要调整你的视图大小,例如

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

(我将 width/height 缩放为 1.97,因为您出于某种原因使用因子 1.97 缩放视图)。