I am playing a video with QML like this:
import QtQuick 2.0
import QtMultimedia 5.0
Video
{
source:'movie.mov'
width: 800
height: 600
autoPlay:true
}
which works, but I would like the movie to be displayed in its original resolution. So whatever movie file I load, I expect the Video element to scale to the video resolution. However,
import QtQuick 2.0
import QtMultimedia 5.0
Video
{
source:'movie.mov'
autoPlay:true
}
will play the video (i can hear sound) but not display anything.
Any suggestions ? (Qt 5.1)
You can bind width and height to the video resolution like this:
import QtQuick 2.0
import QtMultimedia 5.0
Video
{
source:'movie.mov'
width: metaData.resolution ? metaData.resolution.width : 0
height: metaData.resolution ? metaData.resolution.height : 0
autoPlay:true
}
Related
I try to use the SystemTrayIcon in QML using Qt 5.11 (Manjaro with KDE), but when i add
import Qt.labs.platform 1.1
to the QML Code (or 1.0) it doesn't show anything but instantly fails with
/path/to/project exited with code 255
Code example for empty quick project:
import QtQuick 2.11
import QtQuick.Window 2.11
import Qt.labs.platform 1.1
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
}
Problem was conflicting namespaces. Using the import like
import Qt.labs.platform 1.1 as LabsPlatform
LabsPlatform.SystemTrayIcon {
}
works just fine.
In Addition I had to include widgets and use QApplication instead of QGuiApplication.
My question is related to this one: Full-screen desktop application with QML
Here is my MWE:
import QtQuick 2.11
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
Window
{
property string windowFull: "FullScreen";
property string windowWindowed: "Windowed";
width: 400
height: 400
visible: true
title: "Example"
visibility: windowFull;
id: theWindow;
Button
{
onClicked:
{
if (theWindow.visibility === windowWindowed)
theWindow.visibility = windowFull;
else
theWindow.visibility = windowWindowed;
}
}
}
In this example I am trying to go from windowed mode to full screen and vice versa when clicking the button. My problem is that going full screen from windowed mode works, but from full screen to windowed does not. Are there any special requirements that has to be made in order to go windowed mode from full screen?
On Ubuntu, using Window.AutomaticVisibility is making the window visibilty as windowed (default window). Please check the QML window example.
import QtQuick 2.11
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
Window
{
property string windowFull: "FullScreen";
property string windowWindowed: "Windowed";
width: 400
height: 400
visible: true
title: "Example"
visibility: windowFull;
id: theWindow;
Button
{
onClicked:
{
if (theWindow.visibility === Window.FullScreen)
theWindow.visibility = Window.AutomaticVisibility;
else
theWindow.visibility = Window.FullScreen;
}
}
}
I can use AnimatedImage in Qt 5.9 which works on GIFs like this;
import QtQuick 2.7
import QtQuick.Controls 2.2
ApplicationWindow
{
visible: true
width: 640
height: 480
Rectangle
{
width: animation.width;
height: animation.height + 8
AnimatedImage
{
id: animation;
source: "myanimation.gif"
}
Rectangle {
height: 8
width: animation.currentFrame/animation.frameCount * animation.width
y: animation.height
color: "red"
Component.onCompleted: console.log("framecount ", animation.frameCount);
}
}
}
I get a lot of error messages too. This is printed over and over;
QQmlExpression: Expression qrc:/main.qml:26:20 depends on non-NOTIFYable properties:
QQuickAnimatedImage::frameCount
I took my example code from here; http://doc.qt.io/qt-5/qml-qtquick-animatedimage.html
which doen't work at all, something wrong with putting frameCount into a property, so i changed that in my version.
I would like to animate a png like an apng. Apparently there used to be mng support, but it is not there anymore.
So i call QMovie::supportedFormats which returns only GIF (on Windows).
My question:
How can i either use AnimatedImage on a format that supports non-palettised color (eg png etc) or is there another way to animate an image that would work?
Thanks for any info.
It seems like those image formats are not shipped with the standard installation of Qt/QML. You can however install them as a plugin.
See:
Documentation: Qt Image Formats
Code/GitRepository
I am new to QT and want to develop a QT Quick app for the raspberry pi and its touch LCD display. The app should have several screens (sorry, not sure what the right terminology is, with screen I mean a state of the app which fills the whole display of the Raspberry Pi) and there should be buttons to switch between those screens. How is it possible to switch to a different screen when I press a button?
I tried using loader but (right now I am testing on the Desktop not the Raspberry) it opens the qml file in a new window, but I would like to have the content of the original window replaced.
Edit:
Yes, I plan using EGLFS. I enclose some code which does in principle what I want. However, I am not sure if this is the right way to do things: I put the screens I want to have into their own qml file, and toggle their visibility through buttons our mouse areas:
main.qml
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
ApplicationWindow {
visible: true
width: 800
height: 460
title: qsTr("Hello World")
Page1 {
id: page1
visible: true
}
Page2 {
id: page2
visible: false
}
}
Page1.qml
import QtQuick 2.7
import QtQuick.Controls 2.0
Item {
Button {
id: button1
width: 200
height: 40
text: qsTr("To second page")
onClicked: {
page2.visible=true
page1.visible=false
}
}
}
Page2.qml
import QtQuick 2.3
import QtQuick.Window 2.2
Item {
Text {
id: text1
x: 181
y: 153
text: qsTr("Second Page")
font.pixelSize: 12
}
Rectangle {
id: rectangle
x: 252
y: 222
width: 200
height: 200
color: "#000000"
border.color: "#f12525"
}
MouseArea {
id: mouseArea
x: 234
y: 209
width: 244
height: 225
onClicked:{
page1.visible=true
page2.visible=false
}
}
}
I would venture to guess that most likely you want to use Qt5's eglfs mode on the raspberry pi. This gets rid of the normal desktop and runs your Qt5 (regular or QML) app full screen. When I last did this, I needed to compile Qt5 myself. That is something you will either want to figure out cross compiling for, or use a RaspberryPi 3 (the results can then be copied to slower Raspberry Pis if desired). I worked from the guide at https://wiki.qt.io/RaspberryPi2EGLFS
It was pretty trivial to run the program then in a window on a linux desktop or full screen on a Raspberry Pi with touch screen (both the special 7" screen or a generic 22" touch display).
A newer looking alternative to using eglfs is apparently the QtWayland Compositor. I haven't used it, but there is an interesting presentation on using it for full screen embedded applications from the most recent (2017) FOSDEM, available here: https://fosdem.org/2017/schedule/event/device_specific_compositors/
I'm unable to loop a media (mp4 or mp3) with Qt5.4 64 bits (gcc & clang) under Ubuntu 14.04, using QML MediaPlayer. I can't even simply replay the video or audio, it can be played once, that's all.
I add that the problem does not occur under windows 7 64 bits with Qt5.3 (mingw & msvc2012).
Here the simple test code I use :
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtMultimedia 5.0
Item {
width: 640
height: 480
MediaPlayer {
id: video
loops: 2
source : "qrc:si_blue"
}
MediaPlayer {
id: audio
loops: 2
source : "qrc:check"
}
VideoOutput {
id: output
source : video
}
Button {
id: btn
width : 30
height: 30
onClicked: audio.play()
} }