我正在尝试在 QGraphicsView 中通过 rtsp 播放视频 (640 * 360)。但问题是它没有完全适合 View 并且出现了滚动条,这是不应该发生的。此外,我能够在 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 可见区域的大小,而只会调整 View 中可见的场景区域。所以我猜你只需要调整你的 View 大小,例如
view->resize(scene->width()*1.97, scene->height()*1.97)
(我将宽度/高度缩放为 1.97,因为您出于某种原因使用因子 1.97 缩放 View )。
关于c++ - 视频不适合 QGraphicsView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47883617/