c++ - 在“fitInView”呼叫后,十字准线在视频屏幕上的错误位置
问题描述
这个问题与此有关: Video size not fill in QGraphicsView window
我尝试使用 'scene->addLine(...)' 在屏幕上添加一条 'red' 线。但是,在“fitInView”调用之后还差得很远。一开始,十字准线在正确的位置,屏幕中间。但是,当视频开始时(在“fitInView”Lambda 调用之后),它完全消失了。我认为问题在于“场景”的大小和位置不正确。如何使“场景”的大小和起始(x,y)与“视图”相匹配,以便将十字准线绘制在正确的位置。
以下是新代码:
#include <QApplication>
#include <QMainWindow>
#include <QMediaPlayer>
#include <QGraphicsView>
#include <QGraphicsVideoItem>
#include <QGraphicsScene>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
QGraphicsView* view = new QGraphicsView;
QGraphicsScene* scene = new QGraphicsScene(view);
view->setScene(scene);
QMediaPlayer * player = new QMediaPlayer;
QGraphicsVideoItem *item = new QGraphicsVideoItem;
player->setVideoOutput(item);
player->setMedia(QUrl::fromLocalFile("/path/to/tmp1.mp4"));
// player->setMedia(QUrl("rtsp://10/0/8/100:8554/0"); // Live IP camera
scene->addItem(item);
w.resize(640, 480);
QObject::connect(scene, &QGraphicsScene::sceneRectChanged, [=](const QRectF &) { view->fitInView(item); });
player->play();
w.setCentralWidget(view);
w.show();
// Draw a crosshair
QPen p(Qt::red);
qreal centerX, centerY;
centerX = view->width() / 2;
centerY = view->height() / 2;
qreal halfLen = centerX / 2;
(void)scene->addLine(halfLen, centerY, centerX + halfLen, centerY, p);
(void)scene->addLine(centerX, centerY - 30, centerX, centerY + 30, p);
return a.exec();
}
解决方案
推荐阅读
- python - 流媒体直播时如何发送消息和嵌入?| 错误 | 不和谐.py
- python - 如何将包含字符串对象的熊猫数据框列转换为 numpy 数组?
- vba - AfterUpdate On ComboBox:显示选择而不需要其他操作
- arduino - Arduino IDE 给出以下代码错误
- java - Jdbc:Connection 在我的程序中返回 null 怎么办?
- arrays - 在 pngs 上循环运行 ffmpeg 以提高效率?
- ios - SwiftUI 中的 NavigationLink 不再工作
- python - Python pandas 数据重构
- drupal-8 - 如何控制 Drupal 8 monolog dblog 日志级别
- react-native - 在图像上添加覆盖阴影