Customize QVideoWidget and QMediaPlayer Metadata problems
-
I'm able to load and show a video at runtime, but I'm having problem doing some tasks:
- 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); }
- 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
-
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.
-
@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 fromQMediaPlayer
, 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 -
One possible way would be to create your own QAbstractVideoSurface and set it on the player in place of QVideoWidget.
-
@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. -
@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?
-
@jsulm In Qt Creator and in VS 2022 as well.
Qt Creator:
VS 2022:
EDIT: I found the problem... QAbstractVideoSurface has been replaced by the QVideoSink class in Qt6:
https://doc.qt.io/qt-6/qtmultimedia-changes-qt6.htmlEDIT2: I think i will open two different topic since I found different "bug?"