所以我有一个 QMediaPlayer 播放视频,它包含在 QGraphicsVideoItem 内,在 QGraphicsScene 内。我在 QGraphicsScene 中也有文本。QGraphicsView 调整为文本的大小,但不是视频的大小,所以我只能看到视频的左上角。
有没有办法让视频拉伸以填充可用空间?有没有办法让视频在可用空间居中,而不是卡在左上角?
以下是我当前的代码。
videoWidget = new VideoWidget();
QGraphicsView* graphicsView = new QGraphicsView(videoWidget);
QGraphicsScene* scene = new QGraphicsScene(graphicsView);
QGraphicsVideoItem* videoItem = new QGraphicsVideoItem();
QGraphicsTextItem* text = new QGraphicsTextItem("Lorem ipsum ");
text->setDefaultTextColor(Qt::white);
graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
player = new QMediaPlayer();
player->setVideoOutput(videoItem);
graphicsView->setScene(scene);
graphicsView->scene()->addItem(videoItem);
graphicsView->scene()->addItem(text);
playlist = new QMediaPlaylist();
playlist->setPlaybackMode(QMediaPlaylist::Loop);
player->setPlaylist(playlist);
playlistModel = new PlaylistModel();
playlistModel->setPlaylist(playlist);`