Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Move my video rendering label



  • Hi Team,

    I am trying this code and modified it a bit to create my own QLabel class, so I can support mouse move. The code is:

    void videoLbl::mouseMoveEvent(QMouseEvent *ev)
    {
        this->move(ev->x(), ev->y());
    }
    

    But, as soon as I move the video, it flickers and snaps back to the original position, like it repaints and get back to the original rendering position! Now, I am not sure, how to update the newly moved frame(s) to get rendered at the new position.

    Furthermore, if I try to move the same using this code, by hardcoding the position values, it never works, or gets repainted to the original position:

    void videoLbl::updatePlayerUI(QImage img)
    {
        //this->setAlignment(Qt::AlignCenter);
        this->setGeometry(10, 10, 40, 40);
        this->move(10, 10);
        this->setPixmap(QPixmap::fromImage(img).scaled(this->size(), Qt::KeepAspectRatio, Qt::FastTransformation));
    }
    
    

    I am using the following way in my main window class to render my custom Label class:

        m_videoLblDrag = new videoLbl(); // custom QLabel class instance
        m_videoLblDrag->m_vidplayer->loadVideo(fullpath);
        m_videoLblDrag->m_vidplayer->Play();
        ui->videoBox1->layout()->addWidget(m_videoLblDrag);
    

    Please, can you guide me, please?

    • Vicky

  • Lifetime Qt Champion

    Hi
    Did you try to pause the video, then move widget and resume video ?



  • Hello,

    Many thanks for your reply. Yes, after I pause/stop the video, it works as expected! Now what?

    Best Regards!


  • Lifetime Qt Champion

    Hi
    it means you should temporary pause it
    while user moves the Label to avoid the flashing.

    I assume " mouse move." means that user can select the label and move it around on screen.

    Also to make that look good, you should keep the offset into the WIdget where you "grab it"
    like they do there
    https://stackoverflow.com/questions/11172420/moving-object-with-mouse


Log in to reply