QML - change how transition between pages looks - qml

I know this is probably super basic, but I am new to learning QML and have a question about transition between pages.
In this example I have a button with which I want to switch between my 3 pages.
the transition works, but the pages always move from the right-to-the-left-side of the window.
how can I change this? I need the new page to appear as a whole right away.
(e.g. when changing from firstPage to secondPage, for the user it looks like only the AppText changes, because the button is at the same position in both cases)
code example:
App {
id: app
width: px(250); height: px(250)
NavigationStack {
Page {
id: page
navigationBarHidden: true
AppText { text: "startpage" }
SimpleButton{
x: 220; y: 0
onClicked: page.navigationStack.push(firstPage)
}
}
}
Component {
id: firstPage
Page {
navigationBarHidden: true
AppText { text: qsTr("1st page") }
SimpleButton{
x: 220; y: 0
onClicked: page.navigationStack.push(secondPage)
}
}
}
Component {
id: secondPage
Page {
navigationBarHidden: true
AppText { text: qsTr("2nd page") }
SimpleButton{
x: 220; y: 0
onClicked: page.navigationStack.push(page)
}
}
}
}
Any help would be greatly appreciated!

It looks like you're using Felgo, which I think is an extra library on top of Qt. For instance, there is no built-in QML component called NavigationStack. That comes from Felgo. You should mention that in your question to get better help with it.
I've never used Felgo myself, but just looking at the documentation real quick, it looks like you need to define a new transitionDelegate for your needs. Here is the example they give where new pages fade in/fade out.
NavigationStack {
// custom transition delegate
transitionDelegate: StackViewDelegate {
pushTransition: StackViewTransition {
NumberAnimation {
target: enterItem
property: "opacity"
from: 0
to: 1
duration: 1000
}
}
popTransition: StackViewTransition {
NumberAnimation {
target: exitItem
property: "opacity"
from: 1
to: 0
duration: 1000
}
}
}
initialPage: pageComponent
}

Related

Visual feedback (color transition) on TextField?

I have an app with numerous numbers in text fields (in a GridLayout) and would like to visually highlight fields which get changed (something like color changing from the original to red and then back, so something similar).
I am new to animations/transitions and so on, so I would like to ask about what is the correct approach to this.
I was looking at tutorials in Qt Creator but they attach transitions to elements in the QML code already, whereas I would like to get the element by its id and say, now run the highlight transition, without adding something to its code. Is that possible?
You have to implement your own control, derived from Text and add inside all the animation logic you want.
For example:
MyItem.qml
import QtQuick 2.12
Text {
id: txt
property bool hightlight: false
property color textColor: color
property color hightlightColor: "red"
onHightlightChanged: {
if(hightlight)
anim.running = true;
}
SequentialAnimation
{
id: anim
running: false
PropertyAnimation {
target: txt
property: "color"
to: hightlightColor
duration: 500
}
PropertyAnimation {
target: txt
property: "color"
to: textColor
duration: 500
}
ScriptAction {
script: txt.hightlight = false;
}
}
}
Usage:
import QtQuick 2.12
import QtQuick.Controls 2.3
ApplicationWindow {
id: window
title: "Test"
visible: true
height: 250
width: 200
MyItem {
id: item
text: "Hello"
anchors.centerIn: parent
hightlightColor: "red"
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: {
item.hightlight = true;
}
}
}
}

Wix React Native Navigation V2 - custom navigation transitions

Wix React Native Navigation V2 Custom Navigation Transition
Content moderators like myself may get tripped up on this one and mark as duplicate as there are similarly named libraries like React Navigation which have nothing to do with this.
Is there a general way to customize transition animations for push/pop? The documentation seems to be sparse and incorrect after experimenting.
The default push animation moves from right-to-left. I would like to be able to override this in some cases to left-to-right or from top-to-bottom, etc.
Doing this per push/pop doesn't seem to work either when using "animations" and the "x" or "y" properties.
Here's an example of what I've tried.
class MyComponent extends React.PureComponent {
static options(passProps) {
return {
animations: {
push: {
content: {
x: {
from: -1000, to: 0, duration: 300
},
y: {
from: 0, to: 0, duration: 300
}
}
},
pop: {
content: {
x: {
from: 0, to: -1000, duration: 300
},
y: {
from: 0, to: 0, duration: 300
}
}
}
}
}
}
}
But I've tried also per actual command and globally as well with no effect, also tried using "_" in front as some random examples show this.
I'm generally confused on how to customize due to very poor docs on this.
You probably forget enabled: 'true'. I set it globally like:
Navigation.setDefaultOptions({
animations: {
push: {
enabled: 'true',
content: {
x: {
from: 2000,
to: 0,
duration: 200
}
}
},
pop: {
enabled: 'true',
content: {
x: {
from: 0,
to: 2000,
duration: 200
}
}
}
});
and works fine

Dictaphone BB10 in QML

I need make small app on BB10 using QML, which record and play some voice. I have all needed permision (microphone and store file) and this code:
import bb.cascades 1.0
import bb.multimedia 1.0
Page {
property string dataUrl;
Container {
background: Color.create("#001100")
layout: StackLayout {
}
attachedObjects: [
MediaPlayer {
id: audioPlayer
sourceUrl: dataUrl + "/recording.mp4"
},
AudioRecorder {
id: recorder
outputUrl: dataUrl + "/recording.mp4"
}
]
Button {
id: btnRecord
text: "Record"
onClicked: {
recorder.record();
}
}
Button {
id: btnStop
text: "Stop Record"
onClicked: {
recorder.reset();
}
}
Button {
text: "Play Audio"
onClicked: {
audioPlayer.play()
}
}
Button {
text: "Stop Audio"
onClicked: {audioPlayer.stop()
}
}
}
}
After running I can see all buttons, but recording and/or playing is not work. I dont know what is wrong. I cant see any errors.
You're almost there. The problem is your sourceUrl is wrong. The best place to store your recording is in your app's data directory but your QML has no idea where that is.
To solve this you need to expose your app's data path to your QML using C++. You can do this using a property (more info here).
Add the following C++ code under where you create your AbstractPane object (in my case called root). This is normally done in applicationui.cpp.
root->setProperty("dataUrl", "file://" + QDir::currentPath() + "/data");
Now add the dataUrl property to your QML and use it for your sourceUrl:
Page {
property string dataUrl;
Container {
background: Color.create("#001100")
layout: StackLayout {
}
attachedObjects: [
MediaPlayer {
id: audioPlayer
sourceUrl: dataUrl + "/recording.m4a"
},
AudioRecorder {
id: recorder
outputUrl: dataUrl + "/recording.m4a"
}
]
....
}
Edit: Make sure you call audioPlayer.reset() after you've finished recording, this forces the player to reload the recorded audio. If you don't do this your audio playback may be truncated.

How to access the outer components from listitemcomponents in listview bb10 qml?

I am not able to access the Datasource id from inside of the ListItemComponent. Can anyone help me in regards to this?
ListItemComponent {
type: "item"
Container {
id: listviewcontainer
Container {
preferredWidth: 768
layout: StackLayout {
orientation: LayoutOrientation.LeftToRight
}
CustomImageView {
leftPadding: 10
rightPadding: 10
url: ListItemData.from_image
horizontalAlignment: HorizontalAlignment.Left
verticalAlignment: VerticalAlignment.Center
}
Container {
preferredWidth: 538
layout: StackLayout {
orientation: LayoutOrientation.TopToBottom
}
Container {
layout: StackLayout {
orientation: LayoutOrientation.LeftToRight
}
Label {
text: ListItemData.from
textStyle {
base: SystemDefaults.TextStyles.TitleText
color: Color.create("#2db6ff")
}
}
ImageView {
imageSource: "asset:///Home/img.png"
verticalAlignment: VerticalAlignment.Center
}
}//Container
Label {
text: ListItemData.message
multiline: true
textStyle {
base: SystemDefaults.TextStyles.SubtitleText
}
content {
flags: TextContentFlag.Emoticons
}
}
Label {
id: time
text: ListItemData.time
textStyle {
base: SystemDefaults.TextStyles.SmallText
color: Color.create("#666666")
}
}
}//Container
ImageButton {
id: delete_btn
defaultImageSource: "asset:///Icon/delete.png"
pressedImageSource: "asset:///Icon/delete.png"
verticalAlignment: VerticalAlignment.Center
horizontalAlignment: HorizontalAlignment.Right
onClicked: {
deleteMessage(ListItemData.tid, ListItemData.uid);
}
function deleteMessage(tid, uid) {
var request = new XMLHttpRequest()
request.onreadystatechange = function() {
if (request.readyState == 4) {
var mResponse = request.responseText
mResponse = JSON.parse(mResponse)
var mResponseStatus = mResponse.response[0].receive.status;
var mMsg = mResponse.response[0].receive.message;
if (mResponseStatus == 1) {
msg_DataSource.source = "newurl.com" // This line not works here..
msg_DataSource.load(); // This line not works here..
} else if (mResponseStatus == 0) {
}
}
}// end function
request.open("GET", "myurl.com", true);
request.send();
}// deleteMessage
}//ImageButton
}//Container
}//Container
}//ListItemComponent
Here am not able to work out the following two lines
msg_DataSource.source = "newurl.com"
msg_DataSource.load();
I have tried like below but this also not working
listviewcontainer.ListItem.view.dataModel.message_DataSource.source = "myurl.com";
listviewcontainer.ListItem.view.dataModel.message_DataSource.load();
or this
listviewcontainer.ListItem.view.dataModel.source = "myurl.com";
listviewcontainer.ListItem.view.dataModel.load();
Another simplest way to store the object to global variable using the following code which works fine with me.
onCreationCompleted: {
Qt.tabbedPane = tabbedPane;
Qt.homeTab = homeTab;
}
Here I stored tabbedPane in global variable Qt.tabbedPane on page creation Completed.Now I able to access it from ListItemComponent using Qt.tabbedPane.
Hope it helps.
The simplest way to make the data model accessible would be to declare a property alias to your data model wherever it is defined, for example in your ListView QML file. This would make your data model accessible to the top level component in QML from this property alias. In effect, it gives you a global reference to your data model from anywhere else in QML.
For example, if you data model is called msg_DataSource, then in the QML file where it is defined you can create the property alias like this:
property alias myDataModel: msg_DataSource
Then in your ListItemComponent deleteMessage function, you can use myDataModel like this:
myDataModel.source = "newurl.com"
myDataModel.load();
Note: I am sure you could also do this in a more elegant way using signals and slots, but this way should be quicker and easier to understand.

How to play SystemSounds in the Blackberry 10 Dev Alpha Simulator?

I am just trying to run the provided sample code which, as far as I know, should work just fine. Is there anything I am missing or is this a limitation of the simulator.
If so, are there any workarounds?
import bb.cascades 1.0
// To use the MediaPlayer, we must include
// the multimedia library.
import bb.multimedia 1.0
Page {
Container {
id: mainContainer
layout: StackLayout {
orientation: LayoutOrientation.TopToBottom
}
topPadding: 50.0
Label {
id: titleLbl
text: qsTr("SystemSound and MediaPlayer\n Sample App")
multiline: true
textStyle.fontSizeValue: 9.0
textStyle.fontWeight: FontWeight.Bold
textStyle.fontFamily: "Verdana"
textStyle.color: Color.DarkBlue
textStyle.textAlign: TextAlign.Center
horizontalAlignment: HorizontalAlignment.Center
}
// Part 1 of the sample: Playing system sounds.
Container {
id: systemSoundsContainer
layout: StackLayout {
orientation: LayoutOrientation.TopToBottom
}
topMargin: 100.0
horizontalAlignment: HorizontalAlignment.Center
DropDown {
id: soundSelectorDropdown
title: "Sound: "
maxWidth: 600.0
Option {
text: qsTr("Battery Alarm")
value: SystemSound.BatteryAlarm
selected: true
}
Option {
text: qsTr("Browser Start")
value: SystemSound.BrowserStartEvent
}
Option {
text: qsTr("Camera Shutter")
value: SystemSound.CameraShutterEvent
}
Option {
text: qsTr("Device Tether")
value: SystemSound.DeviceTetherEvent
}
Option {
text: qsTr("General Notification")
value: SystemSound.GeneralNotification
}
} // soundSelectorDropdown
Button {
id: systemSoundPlayButton
text: qsTr("Play Selected System Sound")
minWidth: 600.0
onClicked: {
systemSound.play();
}
} // systemSoundPlayButton
} // systemSoundsContainer
// Part 2 of the sample: Playing custom sound files.
Container {
id: customSoundsContainer
layout: StackLayout {
orientation: LayoutOrientation.LeftToRight
}
topMargin: 100.0
Button {
id: customSoundPlayButton1
text: qsTr("Play Sound 1")
layoutProperties: StackLayoutProperties {
spaceQuota: 1.0
}
onClicked: {
// Here we could have created a second MediaPlayer object to
// use to play our sound, but instead we programmatically
// changed the sourceUrl property of the current myPlayer
// MediaPlayer object, and re-used it to play our sounds.
myPlayer.setSourceUrl("asset:///sounds/Doorbell_001.wav")
myPlayer.play()
}
} // customSoundPlayButton1
Button {
id: customSoundPlayButton2
text: qsTr("Play Sound 2")
layoutProperties: StackLayoutProperties {
spaceQuota: 1.0
}
onClicked: {
// Same as above, here we also could have created a second
// MediaPlayer object to use to play our sound, but instead
// we programmatically changed the sourceUrl property of the
// current myPlayer MediaPlayer object, and re-used it to
// play our sounds.
myPlayer.setSourceUrl("asset:///sounds/Doorbell_002.wav")
myPlayer.play()
}
} // customSoundPlayButton2
} // customSoundsContainer
} // mainContainer
// The SystemSound and MediaPlayer objects are attached so
// they can be used in our QML code to play sounds.
attachedObjects: [
SystemSound {
id: systemSound
sound: soundSelectorDropdown.selectedValue
},
MediaPlayer {
id: myPlayer
// sourceUrl: < Set in the Button control's onClicked event handler. >
}
] // Attached objects.
}
Source: https://developer.blackberry.com/cascades/documentation/design/audio_video/playing_sounds_code_sample.html
I suspect that that System Sounds are actually .mp3 or .ogg files internally, where the "Cowbell sample" and "Pull My Beard" are using .wav files. It's a known issue, and has been discussed on the Blackberry Developer forums here and here, and also here, that the simulator does not have the correct codecs to play any sounds except .wav files. The sounds should play correctly on actual hardware.