Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to setPos in QMovie?
Qt 6.11 is out! See what's new in the release blog

How to setPos in QMovie?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.9k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    houmingc
    wrote on last edited by
    #1

    How to move QMovie- gif file from bottom left to bottom right?
    Below is my code
    @
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QPushButton>
    #include <QGridLayout>
    #include <QLabel>
    #include "ticker.h"
    #include <QMainWindow>
    #include <QGraphicsScene>
    #include <QGraphicsRectItem>
    #include <QGraphicsView>
    #include <QMovie>
    #include <QTimer>

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    QWidget *window= new QWidget;
    window->setWindowTitle("My App");

    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();
    

    }

    void MainWindow::video()
    {
    playlist= new QMediaPlaylist();
    player= new QMediaPlayer;
    videoWidget = new QVideoWidget;
    playlist->addMedia(QUrl::fromLocalFile("/opt/VP.mp4"));
    player->setPlaylist(playlist);

    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();
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::move()
    {
    setPos(x()-10,y());

    }
    @

    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        houmingc
        wrote on last edited by
        #3

        Thanks Chris. U are an angel.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved