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

Android SQLite error using cordova
Can we pass param to fragment directly use set method
Custom Android Bottom Menu Bar
how to save an image file in android?
Android - NullPOinterException on my activity
[API GATEWAY][ANDROID] Force close when try to Invoke method
Drag and drop smaller images onto a larger image Android
android studio “ inserting app ” method gettext must be called from the ui thread
cursor.getCount() return 0 while table is not empty
How can I fix Conductor to properly work with Instant Run on Android
How to set the library in a fragment
Save old activity data android
Activate button if the date from is within a given range and if radio button is “yes”
CoordinatorLayout with two RecyclerViews
how to detect android device contains whether virtual home button or physical home button programatically for all SDK versions(all devices)?
i am using quickblox sdk v 2.0f for chat/audio/video call in our app &facing issue that when app runs in background user will not get calls

Categories

HOME
checkstyle
time-complexity
apache-jena
ecmascript-6
object
jelastic
oracle-apex-5
graphics
google-cloud-functions
nsbundle
simulink
gluon-mobile
windows-ce
why3
php-5.6
dynatrace
heat
null-pointer
google-content-api
windows-xp
google-maps-autocomplete
react-toolbox
joptionpane
imageresizer
licensing
jackson-modules
ms-access-web-app
apktool
errbot
realm-mobile-platform
custom-controls
cognos-bi
hibernate-search
nested-lists
yowsup
fiware-cygnus
timing
tex
apns-php
health-monitoring
doc
trigonometry
movilizer
jide
pom.xml
double-click
getchar
lampp
automapper-5
mongotemplate
google-cse
page-replacement
context-switch
reshape
meteor-packages
avspeechsynthesizer
respondcms
cassia
aurora
cda
tfs-workitem
avisynth
pypiserver
microsoft-reporting
flock
morton-number
binomial-theorem
atoi
uncompress
ms-access-2000
exceldatareader
cosine-similarity
packet-sniffers
android-cookiemanager
boost-program-options
crowd
cbind
wcm
malformedurlexception
functional-java
jquery-slider
draw2d-js
authlogic
dsym
git-repo
accesscontrolexception
mbunit
jeromq
printdialog
kaleidoscope
time.h
insert-id
nokia-s40
web-farm
garbage
objectquery
jquery-address
htdocs
lemmatization

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