0

以下代码

QApplication a(argc, argv);
Phonon::MediaObject *media = new Phonon::MediaObject();
Phonon::VideoWidget *video = new Phonon::VideoWidget(NULL);
video->setGeometry(0, 0, 200, 200);
Phonon::createPath(media, video);
Phonon::MediaSource source("1.avi");
media->setCurrentSource(source);
media->play();
video->show();
return a.exec();

给我看一个视频。没关系。但是这个:

QApplication a(argc, argv);
QGraphicsScene scene;
Phonon::MediaObject *media = new Phonon::MediaObject();
Phonon::VideoWidget *video = new Phonon::VideoWidget(NULL);
video->setGeometry(0, 0, 200, 200);
Phonon::createPath(media, video);
Phonon::MediaSource source("1.avi");
media->setCurrentSource(source);
media->play();
QGraphicsProxyWidget * pWidget = scene.addWidget(video,Qt::Widget);
QGraphicsView view(&scene);
view.show();
return a.exec();

向我展示了一个白色背景的小部件。但我的视频在哪里?;) 如果我将音频输出连接到媒体,我会听到电影的声音,所以流正在进行。错误在哪里?(Qt 4.7.0)

4

1 回答 1

0

Displaying QWidget in QGraphicsScene is quite tricky. See QGraphicsProxyWidget description for more information. Basically, the widget you see in QGraphicsView is not real widget. QGraphicsView just redirects paint events to the underlying invisible QWidget. It seems that video redirection is not supported here.

I think you should not put your widget inside scene. Consider placing it above the graphics view, for example.

于 2013-06-28T13:11:38.560 回答