PDA

View Full Version : how to show video output on a round label not a rectangular one?



saman_artorious
11th July 2012, 21:20
I have created a QLabel and play a video inside this QLabel in QT using phonon.(videoPlayer = new Phonon::VideoPlayer(Phonon::VideoCategory, movieLabel);) Now, As you know the shape of this QLabel is rectangular. I want this QLabel to get a form of a Circle. So, that the video is played inside a circle rather than having rectangular shape.

this is the showing movie part:


void VideoPlayer::startMovieSlot()
{
Phonon::MediaObject *media;
Phonon::VideoPlayer *videoPlayer;

media = new Phonon::MediaObject();
media->setCurrentSource(Phonon::MediaSource(QString("./sample.mpg4")));

videoPlayer = new Phonon::VideoPlayer(Phonon::VideoCategory, movieLabel);
// videoPlayer->setFixedSize(QSize(400, 300));
videoPlayer->setFixedSize(800, 500);
// videoPlayer->move(1280-400, 0);

videoPlayer->show();

connect(videoPlayer, SIGNAL(finished()), videoPlayer, SLOT(deleteLater()));
videoPlayer->play(media->currentSource());
}

Now, I want to create the video QLabel and put the output in a round label not a rectangular one, I have drawn a png circle for that to set it on the video:


VideoPlayer::VideoPlayer(QWidget *parent)
: QWidget(parent)
{
// movie = new QMovie(this);
// movie->setCacheMode(QMovie::CacheAll);

qDebug() << "VideoPlayer";

movieLabel = new QLabel(tr("No movie loaded"));
movieLabel->setAlignment(Qt::AlignCenter);
movieLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
movieLabel->setMaximumSize(800, 500);

movieLabel->setBackgroundRole(QPalette::Dark);
movieLabel->setAutoFillBackground(true);

circle = new QPixmap("./circle.png");
imageBox = new QLabel;
imageBox->setPixmap(*circle);

// currentMovieDirectory = "movies";

// startMovieSlot();

// createControls();

createButtons();

// connect(movie, SIGNAL(frameChanged(int)), this, SLOT(updateFrameSlider()));
// connect(movie, SIGNAL(stateChanged(QMovie::MovieState)),
// this, SLOT(updateButtons()));
// connect(fitCheckBox, SIGNAL(clicked()), this, SLOT(fitToWindow()));
// connect(frameSlider, SIGNAL(valueChanged(int)), this, SLOT(goToFrame(int)));
// connect(speedSpinBox, SIGNAL(valueChanged(int)),
// movie, SLOT(setSpeed(int)));

mainLayout = new QVBoxLayout;
mainLayout->addWidget(movieLabel);
mainLayout->addWidget(imageBox);
// mainLayout->addLayout(controlsLayout);
mainLayout->addLayout(buttonsLayout);
setLayout(mainLayout);

// updateFrameSlider();
// updateButtons();

setWindowTitle(tr("Movie Player"));
// resize(400, 400);
resize(1024, 786);
}

my way to solve this problem was this:


circle = new QPixmap("./circle.png");
imageBox = new QLabel;
imageBox->setPixmap(*circle);

but this method doesn't work, moreover the program finishes unexpectedly when I add:

mainLayout->addWidget(imageBox);

any idea how I can show the video output in a circle rather a rectangle?

wysota
12th July 2012, 00:01
Don't use Phonon but rather QtMultimedia module.

saman_artorious
12th July 2012, 07:33
This is not the answer to my question. If you have any claims, please clarify it.
Moreover, anyone could tell me how to mask the circle on the video rectangular output?

ChrisW67
12th July 2012, 08:52
Did you search in the docs for the word "mask"?

wysota
12th July 2012, 09:40
This is not the answer to my question.
Ok, here you go --- "You can't show video output on a round label, videos are not shown on labels but rather using a dedicated widget."

Now go and read about QtMultimedia and implement your own RoundVideoPlayer.