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. Customize QVideoWidget and QMediaPlayer Metadata problems

Customize QVideoWidget and QMediaPlayer Metadata problems

Scheduled Pinned Locked Moved Unsolved General and Desktop
qvideowidgetqmediaplayerqmediametadatatransparenttransparency
9 Posts 3 Posters 2.0k Views
  • 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.
  • T Offline
    T Offline
    TheEnigmist
    wrote on 2 Apr 2022, 18:30 last edited by
    #1

    I'm able to load and show a video at runtime, but I'm having problem doing some tasks:

    1. I want to customize background of my QVideoWidget to a transparent background or at least a color (to understand how it works) but every change I made has no effect (is always black). I tried this:
    QVideoWidget* videoWidget = new QVideoWidget(parent);
    videoWidget->setStyleSheet("background-color: rgba(255, 255, 0, 50);"); // <- NO EFFECT even with Qt::WA_StyledBackground
    
    videoWidget->setAttribute(Qt::WA_NoSystemBackground);
    videoWidget->setAttribute(Qt::WA_TranslucentBackground); // NO EFFECT with these too
    
    //In style.css doesn't work none of them
    QVideoWidget {
        background: transparent;
        background-color: rgba(0,0,0,0);
    }
    
    1. Set the QVideoWidget geometry to be min the size of media is about to playing, but using QMediaMetaData.Resolution I get (-1, -1) as QSize. What I done:
    QMediaPlayer* player = new QMediaPlayer;
    player->setSource(QUrl(videoSrc));
    player->setVideoOutput(videoWidget);
    player->metaData().value(QMediaMetaData::Resolution).toSize() // it prints (-1, -1)
    

    EDIT: I found that sometimes when videoWidget is shown for a little time the background is yellow, but after 1 second it becomes black

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 2 Apr 2022, 18:38 last edited by
      #2

      Hi,

      AFAIR, the video rendering will be done by native backend function which may completely ignore these hints/constraints.

      For example, on macOS, the custom widget paint event will draw explicitly a black background before calling the base class implementation.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      T 1 Reply Last reply 2 Apr 2022, 22:46
      0
      • S SGaist
        2 Apr 2022, 18:38

        Hi,

        AFAIR, the video rendering will be done by native backend function which may completely ignore these hints/constraints.

        For example, on macOS, the custom widget paint event will draw explicitly a black background before calling the base class implementation.

        T Offline
        T Offline
        TheEnigmist
        wrote on 2 Apr 2022, 22:46 last edited by TheEnigmist 4 Feb 2022, 23:49
        #3

        @SGaist
        I see, so there is not way to manipulate it, or at least use some workaround to get rid off native background?

        About MetaData, I found a bizzare behaviour. To get the resolution I need to use metaDataChanged signal from QMediaPlayer, but it works only if the file is on local system, if I load a file inside .qrc resource file I get (-1, -1).
        I'm using Windows 11

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 3 Apr 2022, 19:59 last edited by
          #4

          One possible way would be to create your own QAbstractVideoSurface and set it on the player in place of QVideoWidget.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          T 1 Reply Last reply 4 Apr 2022, 23:53
          0
          • S SGaist
            3 Apr 2022, 19:59

            One possible way would be to create your own QAbstractVideoSurface and set it on the player in place of QVideoWidget.

            T Offline
            T Offline
            TheEnigmist
            wrote on 4 Apr 2022, 23:53 last edited by
            #5

            @SGaist I want try this road, but I cannot include QAbstractVideoSurface, it says the file is missing...
            Tried with VS 2022 and Qt Creator, same error

            J 1 Reply Last reply 5 Apr 2022, 05:18
            0
            • T TheEnigmist
              4 Apr 2022, 23:53

              @SGaist I want try this road, but I cannot include QAbstractVideoSurface, it says the file is missing...
              Tried with VS 2022 and Qt Creator, same error

              J Online
              J Online
              jsulm
              Lifetime Qt Champion
              wrote on 5 Apr 2022, 05:18 last edited by
              #6

              @TheEnigmist said in Customize QVideoWidget and QMediaPlayer Metadata problems:

              QAbstractVideoSurface, it says the file is missing

              Did you add the needed module?
              In case you use Qmake you need "QT += multimedia" in your pro file.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              T 1 Reply Last reply 5 Apr 2022, 07:46
              0
              • J jsulm
                5 Apr 2022, 05:18

                @TheEnigmist said in Customize QVideoWidget and QMediaPlayer Metadata problems:

                QAbstractVideoSurface, it says the file is missing

                Did you add the needed module?
                In case you use Qmake you need "QT += multimedia" in your pro file.

                T Offline
                T Offline
                TheEnigmist
                wrote on 5 Apr 2022, 07:46 last edited by
                #7

                @jsulm Yes, alredy added it, and still it gives missing file error on include...
                I'm on Win 11 with Qt 6.3.0

                J 1 Reply Last reply 5 Apr 2022, 07:48
                0
                • T TheEnigmist
                  5 Apr 2022, 07:46

                  @jsulm Yes, alredy added it, and still it gives missing file error on include...
                  I'm on Win 11 with Qt 6.3.0

                  J Online
                  J Online
                  jsulm
                  Lifetime Qt Champion
                  wrote on 5 Apr 2022, 07:48 last edited by
                  #8

                  @TheEnigmist said in Customize QVideoWidget and QMediaPlayer Metadata problems:

                  still it gives missing file error on include

                  Does this happen when you build your application or is it in QtCreator editor?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  T 1 Reply Last reply 5 Apr 2022, 11:45
                  0
                  • J jsulm
                    5 Apr 2022, 07:48

                    @TheEnigmist said in Customize QVideoWidget and QMediaPlayer Metadata problems:

                    still it gives missing file error on include

                    Does this happen when you build your application or is it in QtCreator editor?

                    T Offline
                    T Offline
                    TheEnigmist
                    wrote on 5 Apr 2022, 11:45 last edited by TheEnigmist 4 May 2022, 15:36
                    #9

                    @jsulm In Qt Creator and in VS 2022 as well.

                    Qt Creator:
                    5353555d-9324-4191-893c-fecc5c693f47-image.png

                    VS 2022:
                    bb6a6442-08eb-47b0-8094-ebbe6633792b-image.png

                    EDIT: I found the problem... QAbstractVideoSurface has been replaced by the QVideoSink class in Qt6:
                    https://doc.qt.io/qt-6/qtmultimedia-changes-qt6.html

                    EDIT2: I think i will open two different topic since I found different "bug?"

                    1 Reply Last reply
                    1

                    5/9

                    4 Apr 2022, 23:53

                    • Login

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