我使用Qgraphicsvideoitem使用Qmediaplayer显示视频。 现在,如果我有圆形项目,我该如何将视频屏蔽到该项目中。
这是我的代码和图片:
VideoClass::VideoClass(QGraphicsVideoItem *parent):QGraphicsVideoItem(parent)
{
QMediaPlayer *player = new QMediaPlayer(this, QMediaPlayer::VideoSurface);
QMediaPlaylist *playlist = new QMediaPlaylist;
playlist->addMedia(QUrl::fromLocalFile("/root/Desktop/Content/Robotica_1080.wmv"));
playlist->setPlaybackMode(QMediaPlaylist::Loop);
player->setPlaylist(playlist);
player->play();
player->setVideoOutput(this);
}
void VideoClass::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QGraphicsVideoItem::paint(painter, option, widget);
painter->drawEllipse(0, 0, 400, 400);
}
QRectF VideoClass::boundingRect() const
{
return QRectF(0,0,400,400);}
答案 0 :(得分:1)
我认为您想要将视频裁剪为您正在绘制的路径。如果是这样,请使用shape和opaqueArea虚函数来执行此操作。并且不要忘记设置标志QGraphicsItem :: ItemClipsToShape。