我正在尝试设计一个应用程序来播放多个视频(媒体)文件并允许用户对每个文件进行修改(例如,缩放、旋转、反转视频等)。我从学习开始Phonon
,但在研究了一段时间后,读到 >= 不再支持它(或者它的支持值得怀疑)Qt5
。所以然后我回去了,现在我在看 qtmultimedia - QMediaPlayer
。虽然我来自 c#-WPF 背景,但我在 Qt-C++ 上做了一些早期的工作。但这一次,我对必须使用哪些小部件感到困惑和困惑。可以在和QMediaPlayer
上显示其输出(视频QVideoWidget
)。由于我需要旋转等功能,我相信我必须合并 QGraphicsScene/View。QGraphicsVideoItem
QAbstractVideoSurface
<1> 那么方法应该是什么?我这样做了:使用QVideoWidget
->QGraphicsProxyWidget
通过它的setWidget
() 添加了这个(虽然setWidget
() 需要QWidget
* 并且QVideoWidget
不是从QWidget
我在 Qt 助手中看到的那样派生 - 为什么这允许顺便说一句?) -> 将它添加QGraphicProxyWidget
到QGraphicsScene
via addItem
() ->在构造它时将其添加到 -> 添加到QGraphicsScene
via ( ) 。这样好吗?何时使用和?QGraphicsView
QGraphicsView
QMainWindow
setCentralWidget
QGraphicsVideoItem
QAbstractVideoSurface
<2> 当QVideoWidget
以以下方式添加多个时,我看不到任何视频或视频QVideoWidget
本身(我已经画了以区分它)。我究竟做错了什么?(虽然有音频输出):
QVideoWidget *pVideoWidget1 = new QVideoWidget(0);
pVideoWidget1->setPalette(QPalette(QColor(255,0,0),QColor(0,255,0)));
QVideoWidget *pVideoWidget2 = new QVideoWidget(0);
pVideoWidget2->setPalette(QPalette(QColor(255,0,0),QColor(0,0,255)));
m_pMediaPlayer1 = new QMediaPlayer(this);
m_pMediaPlayer2 = new QMediaPlayer(this);
m_pMediaPlayer1->setVideoOutput(pVideoWidget1);
m_pMediaPlayer2->setVideoOutput(pVideoWidget2);
m_pCustomGraphicsProxy1 = new CustomGraphicsProxy(0); //this is just a class derived from QGraphicsProxyWidget to implement drag and drop of videos
m_pCustomGraphicsProxy2 = new CustomGraphicsProxy(0);
m_pCustomGraphicsProxy1->setWidget(pVideoWidget1);
m_pCustomGraphicsProxy2->setWidget(pVideoWidget2);
QGraphicsScene *pGraphicsScene = new QGraphicsScene(this);
QGraphicsLinearLayout *pGraphicsLinearLayout = new QGraphicsLinearLayout;
CustomGraphicsProxy* button = new CustomGraphicsProxy(0);
button->setWidget(new QPushButton); //this i can see
CustomGraphicsProxy* button1 = new CustomGraphicsProxy(0);
button1->setWidget(new QPushButton); //this i can see too
pGraphicsLinearLayout->addItem(button);
pGraphicsLinearLayout->addItem(m_pCustomGraphicsProxy1); //can't see
pGraphicsLinearLayout->addItem(m_pCustomGraphicsProxy2); //can't see
pGraphicsLinearLayout->addItem(button1);
CustomGraphicsProxy *temp = new CustomGraphicsProxy(0);
temp->setLayout(pGraphicsLinearLayout);
pGraphicsScene->addItem(temp);
temp->show();
m_pGraphicsView = new QGraphicsView(pGraphicsScene, this);
setCentralWidget(m_pGraphicsView);
QObject::connect(m_pCustomGraphicsProxy1, SIGNAL(sigNewFileDragDropped()), this, SLOT(sloPlayOnWindow1()));
QObject::connect(m_pCustomGraphicsProxy2, SIGNAL(sigNewFileDragDropped()), this, SLOT(sloPlayOnWindow2()));
//just for testing - this gives only audio no video can be seen
m_pMediaPlayer1->setMedia(QUrl::fromLocalFile("d:/z.avi"));
m_pMediaPlayer1->play();
<3> 在我进一步研究之前,我是在 Qt 中选择正确的工具来操作我之前提到的视频还是需要做其他事情?