android


QML Canvas on Android, Orientation Issue


I'm fairly new to QML (on Android) so forgive me if this is a trivial thing. I'm trying to use the Canvas object to draw some custom graphs etc. However I can't get it to behave nicely with changing screen orientation. If I start my app in portrait orientation, it looks ok until I switch to landscape. Same happens if I start it landscape. Everything is ok until I go portrait. How can I fix this behavior? Here's a simple test I'm having trouble with:
import QtQuick 2.2
import QtQuick.Window 2.1
Window {
visible: true
visibility: Window.FullScreen
Rectangle {
anchors.fill: parent
color: "red"
Canvas {
anchors.fill: parent
onPaint: {
var ctx = getContext("2d")
ctx.fillStyle = "blue"
ctx.fillRect(0, 0, width, height)
}
}
}
}
Here's what happens. If I start the above app portrait, it fills the screen with both the red background rectangle and the blue canvas on top of it (I can actually see it drawing the both). When I go landscape, this is what I end up with.
The canvas does not fill the entire screen anymore. It seems to be now a perfect square and clipping the right side off (It's not stretching. You'd see this if there was more content). Similar thing happens if I start landscape and go portrait:
Answering my own question as one of the possible solutions. It looks like the "anchors.fill: parent" lines in my original code do not update the width and height properties in the respective levels by default. The following code seems to gets rid of the problem:
import QtQuick 2.2
import QtQuick.Window 2.1
Window {
id: root
width: Screen.width
height: Screen.height
visible: true
visibility: Window.FullScreen
Rectangle {
anchors.fill: parent
width: parent.width
height: parent.height
color: "red"
Canvas {
anchors.fill: parent
width: parent.width
height: parent.height
onPaint: {
var ctx = getContext("2d")
ctx.fillStyle = "blue"
ctx.fillRect(0, 0, width, height)
}
}
}
}
I'm not actually too sure about my previous answer anymore. Might have been just lucky incidence. I think I found the real reason for this behavior. If I deploy the application so that it uses the Ministro service on my phone, then I'll get this buggy behavior. But if I bundle Qt from my build machine into the package, everything works fine. Tested twice with the same project and same source files... I have Ministro 9.6.8 on my phone and the latest official Qt on my machine.

Related Links

Imageview Src path in Android in Appium
How to simulate the tag touch from other application
very slow input from bluetooth barcode scanner to edittext
Android Google Cloud Storage with “Client ID for Android application” is Forbidden?
How to pass/save the data from activity A to B and then to B?
Android wear settings activity
Android: SqlLiteDatabase delete does not work for certain ID
scanning result of ibeacon on android never shown on the smartphone
NFC tag(for NfcA) scan works only from the second time
Xamarin WebViewClient onLoadResource/onPageFinished
Displaying one item from a ListView of many items like a SlotMachine
Size of MediaStyle LargeIcon
How to disable or capture the home key click event
Dynamically Creating Multiple TextViews in LinearLayout
Sending data from ASP.NET to android
White background while switching to webview

Categories

HOME
batch-file
notepad++
microsoftgraph
scikit-learn
dns
redux-form
battery
xbee
soa
pyqt4
odoo-8
mql5
google-schemas
openstreetmap
libc
onedrive-api
shared-libraries
3nf
job-scheduling
asp.net-mvc-viewmodel
google-container-registry
digital-signature
nim
connector
boost-icl
postscript
xunit
pic32
opentk
corpus
vex
google-cast
mockjax
deltaspike
reason
imagenet
android-augmented-reality
opensmpp
android-exoplayer
apache-spark-dataset
java-6
cup
er-diagram
check-mk
cpu-cache
pybrain
universal-analytics
baidu
juice-ui
choice
flex-monkey
winusb
preprocessor
jquery-jscrollpane
mapinfo
installshield-2010
tracker-enabled-dbcontext
cda
kiosk
aspen
phpgrid
assertion
oracle-spatial
mod-proxy
omnifaces
diff3
rrule
jbake
primitive-types
formview
appserver
machine-instruction
high-resolution
embedded-fonts
dtmf
gpars
mvc-editor-templates
pstack
sentestingkit
iboutlet
inkcanvas
luabind
convention
jquery-tools
listactivity
strsep
nhprof
rowlex
murmurhash
lxr
data-mapping
visualj#
fdf
dsoframer
lemmatization
blind

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App