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. Painting over a QVideoWidget
Forum Updated to NodeBB v4.3 + New Features

Painting over a QVideoWidget

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 3.0k Views 1 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.
  • J Offline
    J Offline
    Jonathan Levanon
    wrote on 24 Jun 2018, 10:11 last edited by
    #1

    I'm trying to paint on a qvideowidget (drawing text now, maybe need something more complex later).

    However, when subclassing qvideowidget and overriding the paint event, the text is not painted. Is there another way to paint on top of a qvideowidget?

    This is the code I have so far:

    #include "videow.h"
    
    videoW::videoW(QString dir, QString listFile) {
        player = new QMediaPlayer(this);
        playlist = new QMediaPlaylist(player);
        updatePlayList(dir);
        player->setMedia(playlist);
        player->setPlaybackRate(1);
        player->setVideoOutput(this);
    
    }
    
    void videoW::paintEvent(QPaintEvent *event){
        qDebug() << "Painting";
        QPainter p(this);
        p.drawText(QRect(200,0,1000,200), "Fwejaf;ljflawejf;wj wkjfklweajfl w");
    
    }
    
    void videoW::play(){
        std::cout << "Start playing" << std::endl;
        std::cout << playlist->currentIndex();
        player->play();
    }
    
    void videoW::updatePlayList(QString dir){
        QDir recoredDir(dir);
        QStringList filters{"*.mp4", "*.avi"};
        QStringList filesToDisp = recoredDir.entryList(filters);
        bool getNames = videoNames.isEmpty();
        for (int i = 0; i < filesToDisp.size(); ++i) {
            QString fileName = filesToDisp[i];
            if (isSupported(fileName) && ((!videoNames.isEmpty() && videoNames.contains(fileName)) || getNames)) {
                QMediaResource c(QUrl::fromLocalFile(dir + "/" +fileName));
                playlist->addMedia(c);
                if (getNames){
                    videoNames.append(fileName);
                }
            }
        }
    
        std::cout << "Loaded " << playlist->mediaCount() << " videos for display" << std::endl;
    }
    
    /**
     * @brief videoDisplay::isSupported - check if a file can be played
     * @param name
     * @return
     */
    bool videoW::isSupported(QString name) {
        if (name.indexOf(".avi") > -1 || name.indexOf(".mp4") > -1) {
            return true;
        }
        return false;
    }
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 24 Jun 2018, 10:15 last edited by
      #2

      Hi
      Does the video show ? as you dont seems to call base PaintEvent.
      Anyway, i was wondering.

      If you overlay say a QLabel. Does that work ?
      If not critical to actually draw yourself.

      also, this seems to work
      https://forum.qt.io/topic/1024/paint-over-qvideowidget/9

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jonathan Levanon
        wrote on 24 Jun 2018, 10:51 last edited by Jonathan Levanon
        #3

        I've tried with a label, but I was struggling with making it transparent. Will try the link you mentioned, thanks

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jonathan Levanon
          wrote on 26 Jun 2018, 08:31 last edited by
          #4

          Thanks @mrjj , your overlay tip got me looking for that term and I found https://stackoverflow.com/questions/19199863/draw-rectangular-overlay-on-qwidget-at-click

          Took the second answer, and its working.

          M 1 Reply Last reply 26 Jun 2018, 08:40
          1
          • J Jonathan Levanon
            26 Jun 2018, 08:31

            Thanks @mrjj , your overlay tip got me looking for that term and I found https://stackoverflow.com/questions/19199863/draw-rectangular-overlay-on-qwidget-at-click

            Took the second answer, and its working.

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 26 Jun 2018, 08:40 last edited by
            #5

            @Jonathan-Levanon
            Good found. nice overlay class :)

            1 Reply Last reply
            0

            5/5

            26 Jun 2018, 08:40

            • Login

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