Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to setPos in QMovie?
houmingc last edited by
How to move QMovie- gif file from bottom left to bottom right?
Below is my code
MainWindow::MainWindow(QWidget *parent) :
QWidget *window= new QWidget;
ml = new WidgetMarqueeLabel(this); ml->setTextFormat(Qt::RichText); ml->setAlignment(Qt::AlignBottom); ml->setText("this is a very long text, weather is very hot"); ml->setFont(QFont("Arial", 20,20)); QGridLayout *layout= new QGridLayout; video(); QLabel* label= new QLabel; QMovie* movie = new QMovie("/home/ubuntu/Desktop/graphic.gif"); label->setMovie(movie); movie->start(); QTimer *timer = new QTimer(); connect(timer,SIGNAL(timeout()),movie,SLOT(move())); //??How to move QMovie timer->start(60); layout->addWidget(videoWidget,0,0); layout->addWidget(videoWidget1,0,1); layout->addWidget(ml,1,0,1,2); layout->addWidget(label,2,0,1,2); window->setLayout(layout); window->show();
playlist= new QMediaPlaylist();
player= new QMediaPlayer;
videoWidget = new QVideoWidget;
playlist1= new QMediaPlaylist(); player1= new QMediaPlayer; videoWidget1 = new QVideoWidget; playlist1->addMedia(QUrl::fromLocalFile("/opt/hotgirl.mp4")); player1->setPlaylist(playlist1); player->setVideoOutput(videoWidget); player1->setVideoOutput(videoWidget1); playlist->setCurrentIndex(1); playlist1->setCurrentIndex(1); player->play(); player1->play();
Hi and welcome,
There are a couple of problems with your code.
First of all you're leaking memory like crazy. window does not have a parent and you never delete it, so it's a leak. The same goes for movie, timer, playlist1, player1 and videoWidget1.
Then, you make a ml a child of MainWindow (by passing this in the constructor), but put it in a layout of window, which switches its parent to window. While not an error, it's just wasteful. Just don't give it a parent if it's going in a layout.
Now to the moving problem. You didn't write what setPos is, but I assume your intention is to animate the position of label displaying the movie.
In your code you placed the label inside a layout, so it's the layout that governs the size and position of the label. You can't override it.
If you want to manually set the position of the label don't put it in a layout. Give it a parent (e.g. window) and then use setGeometry.
Also, there's a cleaner way to achieve the same without a timer. Check the example of QPropertyAnimation.
houmingc last edited by
Thanks Chris. U are an angel.