qt


how to create multiscreen application in Qt QML


Very simple question.
This is regarding Qt 4.8.5, QML, QtQuick 1.1
I cannot understand how screen transitions are happening in QML and how to code.
For simplicity consider I have 3 different screens in 3 different QML files.
1.Home Screen
2.Setting Screen
3.Help Screen
all with width: 640 and height:480
Each screen in different and has different child inside.
Now I have a button in Home screen to go the Setting Screen which has a back button to come back. And then in both 1 and 2 there is a help button which shows the Help Screen.
Now how should my main.qml file be???
for simplicity consider the screens have only the navigation buttons.
Can someone post me a code.?
If you are sure that your app will stay fixed to those 3 screens, you can get away with something as simple as this:
Rectangle {
id: app
anchors.fill: parent
Row {
anchors.centerIn: parent
Button {
text: "settings"
onClicked: set.visible = true
}
Button {
text: "help"
onClicked: help.visible = true
}
}
}
Rectangle {
id: set
anchors.fill: parent
color: "red"
visible: false
Button {
anchors.centerIn: parent
text: "close"
onClicked: set.visible = false
}
}
Rectangle {
id: help
anchors.fill: parent
color: "blue"
visible: false
Button {
anchors.centerIn: parent
text: "close"
onClicked: help.visible = false
}
}
You have all 3 "screens" in a sequence so that the app screen is on the bottom, with settings and help on top. Then you can switch screens by simply controlling the visibility.
If you want a more dynamic solution, follow my hints from the comments to implement a simple stack view, it is quite easy and will be a good exercise to learn QML.
You definitely don't want to follow the example of Konstantin T., and it is a mystery why such a flawed example was upvoted in the first place. That approach will destroy your app screen every time you open settings or help, going back you will not go to your previous screen, but to a brand new instance of it, losing all your previous input. Also, putting a mouse area on top of that guarantees you will not be able to interact with any of the screen's element.
You can use Loader element. It is used to dynamically load visual QML components. It can load a QML file (using the source property) or a Component object (using the sourceComponent property).
For example:
Item {
width: 200; height: 200
Loader {
id: pageLoader
source = "Page1.qml"
}
MouseArea {
anchors.fill: parent
onClicked: pageLoader.source = "Page2.qml"
}
}

Related Links

Draw 32x32 Tiled Images in QT
QTreeView with columns
QT Creator: undefined reference to 'WinMain#16'
Adding a text to the QTabWidget
adding shapelib to Qt's project
QSignalMapper with signal argument and extra argument
Error while set up absolute image path in QML/QT (under Windows)
QProcess not work with start but work with startDetached
QSocketNotifier: socket notifiers cannot be disabled from another thread
qmake eval function “always true” for string literals
Implementing a GUI Shell in qt
Get rid of Qt's dotted outline on QListView items
How to stop the transition animation in QML?
How does Qt on Windows draw exactly? Does it call GDI internal to draw?
QML: aliases to children properties
QTreeView remove decoration/expand button for all items

Categories

HOME
python-2.7
writefile
qooxdoo
turbojpeg
linker
angular-meteor
minecraft
sympy
specifications
migrate
csrf
ex
webstore
texas-instruments
pywinauto
jqxgrid
exec-maven-plugin
psql
adobe-illustrator
neo4j.rb
altium-designer
python-appium
sap-lumira
acrobat
spring-annotations
sfml
bitbake
social-networking
mapnik
steam-web-api
knights-tour
autoencoder
assertions
bluemixtools
gitolite
rdp
flowchart
right-click
plane
contactless-smartcard
elasticsearch-aggregation
httphandler
git-tfs
permission-denied
axis
uiautomatorviewer
password-hash
sonicmq
phppgadmin
embedded-v8
popen
lvalue
predicates
mpmovieplayercontroller
jsonix
mathml
oci
declarative
meld
ajaxmin
json-spirit
mousehover
directx-9
auto-generate
jnlp
wso2ml
ngcordova
actionpack
sunos
zend-mail
windows-messages
code-complexity
sql-function
meteor-collections
nodeload
django-sites
iosched
spring-security-acl
quickgraph
ember-table
objective-c-runtime
user-forums
system-information
pageheap
fitch-proofs
algol68
netstream
background-repeat
drawimage
uipasteboard
kohana-auth
multiple-users
3-tier
odac
j2mepolish
raw-data
cleartype
getimagesize
yahoo-maps
subtext
downloadfile

Resources

Encrypt Message