Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Solved Painting over a QVideoWidget

    General and Desktop
    2
    5
    1948
    Loading More Posts
    • 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.
    • Jonathan Levanon
      Jonathan Levanon last edited by

      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 Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • Jonathan Levanon
          Jonathan Levanon last edited by Jonathan Levanon

          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 Reply Quote 0
          • Jonathan Levanon
            Jonathan Levanon last edited by

            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.

            mrjj 1 Reply Last reply Reply Quote 1
            • mrjj
              mrjj Lifetime Qt Champion @Jonathan Levanon last edited by

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

              1 Reply Last reply Reply Quote 0
              • First post
                Last post