Some codecs alow alpha transparency, like flv, Mov and Webm. I am about to build a QT app and i want to know if it will be possible to make a video player using QML which will support transparency and i will be able to see the background of my app even when the video is playing.
You can set a widget to have a level of transparency, so if the video stream is also transparent it should show transparent to the widget and then if the widget is also transparent then through that.
Have you already looked at the QML Video example which ships with the current QTCreator / QT 5.1.1 SDK package?. If you wish to draw a transparent/translucent video window, you can modify the 'opacity' property of a QML VideoOutput element to have translucent Video overlay.
You can build the example if you download and install the SDK.
Here's is the online link to the example:
QML Video Example
Take a close look at this file:
VideoItem.qml
You can modify the opacity as shown below:
import QtQuick 2.0
import QtMultimedia 5.0
VideoOutput {
id: root
height: width
source: mediaPlayer
opacity: 0.7 // Set the opacity as you wish
...
You can play around with the example by importing any type of video files you wish.
Related
I'm trying to show a gif file in QT app, using the approach provided in the link: https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/widgets/movie?h=5.15
Approach makes use of QMovie object set in a QLabel.
The example works well and fine.
But if I enable High DPI scaling for the app, the gif becomes all pixelated. Please see the screenshots below.
This is the line that I add to enable High DPI scaling.
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
Any ideas to get this fixed ?
I have tried the following fixes already:
setScaledSize for the QMovie object
setScaledContents(true) for the QLabel
QT version I'm using is 5.15.2 and platform is Windows.
A GIF picture cannot have more than 256 unique colours. When you load such an image into Qt, it is internally represented in that exact format with the palette (of 256 colours) from the GIF representation, even if your hardware might be able to display many more colours.
This also means that when you scale such an image, Qt is not allowed to extend the colour space to render in-between colours - This means that scaled GIF pictures generally have to look much worse than scaled high-colour images.
The solution to this is either to transform the QImage you created from a GIF picture into a format with a larger colour space before scaling it (with QImage::convertToFormat) or, better still, don't use GIF images at all. After all, GIF is a format developed 30 years ago and has never really been updated to adapt to modern hardware, and using it, you artificially limit your programs to the capabilities of that format.
It seems at this moment there is no way to render sharp gifs when scaled using QMovie and QLabel. I have filed a bug for the same in QT bug tracker.
Meanwhile I have found a workaround that works fine. It is done making use of QML in the QWidget system, using QQuickWidget.
Let me add the full steps here, so that it is helpful to anyone else who run into this problem:
First we need to add support for Qml and QuickWidgets. I use CMake and Visual Studio. Hence I add the below lines in the CMakeLists.txt file. Equivalent changes needs to be made in the .pro file, if QT Creator is used instead.
# I'm only adding the relevant lines for brevity
find_package(Qt5 COMPONENTS Qml QuickWidgets)
target_link_libraries(${APP_TARGET_NAME}
Qt5::Qml
Qt5::QuickWidgets)
# Note the --qmldir switch
add_custom_command (TARGET ${APP_TARGET_NAME} POST_BUILD
COMMAND ${QTDIR}/bin/windeployqt
--qmldir ${CMAKE_CURRENT_SOURCE_DIR}/qml
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${APP_TARGET_NAME}.exe)
Then create a spinner.qml file inside a folder named qml:
import QtQuick 2.15
Rectangle {
width: 12
height: 12
AnimatedImage {
y: 5
width: 12
height: 12
id: spinner
source: "img/spinner.gif"
speed: 1.0
}
}
And then load the qml file using QQuickWidget and add the QQuickWidget instance to the QWidget layout.
QHBoxLayout *main_layout = new QHBoxLayout();
auto *spinner_gif = new QQuickWidget(QUrl::fromLocalFile(":/spinner.qml"));
main_layout->addWidget(spinner_gif);
this->setLayout(main_layout);
The gif that shows up won't be pixelated even when scaled and we can see the GPU in use, in the Task Manager, as expected for a QQuickWidget.
I am using QML component WebEngineView, It has been observed that, scrollbar is by default implemented in WebEngineView, but there is no interface to change the width of scrollbar. This is required in my use case where I cannot use swipe, I can use only mouse drag operation on scrollbar of the WebEngineView in order to view all hidden part of the web content where length is outside the view port area. Since Scrollbar size of WebEngineView( default is very small 15pix )its quite difficult to drag exactly on the area and drag using mouse.
Can Some one suggest how to customize the scrollbar of WebEngineView?
or
I can find webengine source code, then modify and build for the purpose?
or
Any Style Can apply on WebEngineView ?
I am using Qt 5.6.2
Qt Webengine Source code Observation:
QML Webengineview is not set any scrollbar width internally, instead it uses back-end scrollbar probably of chrome’s.
WebEngineView uses the scrollbar that comes from the Chromium backend and there is no QML or C++ API to customize it directly. However WebEngine supports to change these scrollbar styles in CSS, so the only thing you can do is to install a user script which applies a bigger width on all -webkit-scrollbar.
See this related example: http://doc.qt.io/qt-5.10/qtwebengine-webenginewidgets-stylesheetbrowser-example.html
And your stylesheet could look like this:
::-webkit-scrollbar {
width: 40px;
}
I am using Qt 5.5.0 and Qt3D 2.0.
I want to display video as texture.
I can display and rotate only one image.
How can I add a video instead of an image?
I'm trying to get an alpha-blending effect in QML with a video in RGBA.
Now the problem is that the Video Item supplied by QtMultimedia actualy opens an overlaying window in the QtQuick scene, so I don't think it's possible to alpha-blend other QML elements with the Video element (I sure hope I'm wrong, but I can't find a solution).
So another way would be rendering a video myself in a class that inherits from QQuickItem, in the updatePaintNode method.
Has anyone seen anything like this before? Is it even possible if the guys behind QtMultimedia couldn't achieve it?
Can I maybe change the background of the MediaPlayer element, maybe to be transparent or just a color in QML?
So far I was thinking about QAbstractVideoSurface and QVideoFrame but I have no idea how to render it onto the QSG, or even how should the GeometryNode look for a video.
The best solution would be to get the alpha-blending with other QML Elements for example in:
Rectangle {
width: 1024
height: 768
color: "yellow"
focus: true
Video {
id: video
anchors.fill: parent
source: "alpha-video.mov"
autoPlay: true
}
}
Thanks in advance!
I tried a few things, but in the end I used the Qt example called VideoWidget that uses QAbstractVideoSurface and QVideoFrame, and painted the frames in a QQuickPaintedItem, using MediaPlayer to load the data from QML.
It's important to put ARGB32 on top of the QList that describes the supported pixel formats in the QAbstractVideoSurface, unfortunately the Qt logic is that they take the first availibe format and that's why the native Video element doesn't show the alpha channel (it plays the video in RGB32, either that or it's a thing with the overlaying window in the native element instead of painting it in the QtQuick Scene Graph).
I'm writing a QML application that displays a collection images.
To display next and previous image I use a ParallelAnimation to animate the x coordinate translation but the result is ugly: images animate but there is a flicking during the animation.
I've tried with opengl viewport and some optimizations (see here) but no success.
try adding view->setAttribute(Qt::WA_NoSystemBackground);
in main.cpp