c++ - 视频不适合 QGraphicsView

标签 c++ qt qgraphicsview

我正在尝试在 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/

相关文章:

c++ - 我如何创建一个循环来检查用户输入以查看它是否是现有文件?

c++ - 为什么我在 Qt 中实现交互式 QGraphicsView 时无法更改鼠标光标?

c++ - Qt 中的 GIF 动画

c++ - 如何从.so文件导入python模块?

c++ - 无法在 C++ 中跟踪 Visual Studio 入口点

QtCore/QtGlobal : No such file or directory

qt - QDBusAbstractAdaptor 对象不导出已实现的 dbus 接口(interface)

c++ - 无法在 qgraphicsItem 中为 QTransform 设置动画

c++ - 具有复杂输出或幅度+相位的 C/C++ Goertzel 算法?

python - 如何在 PyQt 中编写图像按钮?