Behavior not working in inheritance sometimes - qt

I found strange behavior when using Behavior. I want to animate the height of a Pane when I changed the Pane's height:
ModulePanelCard.qml:
import QtQuick 2.7
import QtQuick.Controls 2.1
import QtQuick.Controls.Material 2.1
Pane{
id: root
property bool isToggled: true
Material.elevation: 6
height: root.isToggled? 300: 100
Behavior on height {
NumberAnimation{duration: 300}
}
Button{
text: "click"
anchors{top: parent.top; right: parent.right; left: parent.left}
height: 40
onClicked: root.isToggled = !root.isToggled
}
}
main.qml:
import QtQuick.Controls 2.1
import QtQuick.Controls.Material 2.1
import QtQuick 2.6
ApplicationWindow {
id: window
width: 400
height: 400
visible: true
ModulePanelCard{
id: strategyCard
width: 300
anchors{top:parent.top; right: parent.right; left: parent.left}
}
}
OK. The animation shows up and everything goes fine! However when I want to do some inheritance, i.e. inherit from ModulePanelCard, strange things happen:
StrategyCard.qml
import QtQuick 2.7
ModulePanelCard{
}
main.qml:
import QtQuick.Controls 2.1
import QtQuick.Controls.Material 2.1
import QtQuick 2.6
ApplicationWindow {
id: window
width: 400
height: 400
visible: true
StrategyCard{
id: strategyCard
width: 300
anchors{top:parent.top; right: parent.right; left: parent.left}
}
}
If I put nothing into StrategyCard, everything is the same as previous. However, when I insert even one property or signal to StrategyCard, the animation of the height is just gone! The Behavior on the height won't work anymore!
StategyCard.qml:
import QtQuick 2.7
ModulePanelCard{
property string xxx: "hello"
}
However, if I put the Behavior statement into StrategyCard.qml, then the animation comes back!
New StrategyCard.qml:
import QtQuick 2.7
ModulePanelCard{
property string xxx: "hello"
Behavior on height {
NumberAnimation{duration: 300}
}
}
What happened? Anyone helps me? Thanks!
My development environment is: Windows 10 64bit, Qt 5.9.0 64bit for VS2015, Qt Creator 4.3.0

Related

QML Dialog positioning in ApplicationWindow

I am finding it impossible to position a Dialog central to my ApplicationWindow in QT 5.12
import QtQuick 2.7
import QtQuick.Controls 2.2
import QtQuick.Dialogs 1.2
ApplicationWindow {
id:mainApplicationWindow
visible: true
height: 500
width: 500
Item {
anchors.centerIn: parent
MainWindowMessageDialog{
id: messageDialog
}
}
Component.onCompleted: {
messageDialog.open()
}
}
With MainWindowMessageDialog.qml
import QtQuick 2.0
import QtQuick.Dialogs 1.2
Dialog {
title: "There seems to be a problem"
standardButtons: StandardButton.Ok
onAccepted: {
this.close()
}
}
Gives me the image below. I've tried adding a fixed z position but nothing seems to shift the Dialog downwards into the window. I've tried MainWindowMessageDialog on its own outside of an Item. Nothing seems to shift it? Am I missing something?
This turned out to be an issue of modality.
https://bugreports.qt.io/browse/QTBUG-82737?jql=text%20~%20%22MessageDialog%22
Adding
modality: Qt.ApplicationModal
Did the trick

Blur part of background image in QML/Qt

I'm fairly new to QML/Qt. Basically I would like to know how to apply a blur to the inside of the white rectangle seen on the photo below and only the inside so that it blurs the part of the background image within the rectangle. I tried doing this in a normal Qt project but don't think its possible without using QML.
It's possible. Use ShaderEffectSource item:
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
import QtGraphicalEffects 1.12
import "qrc:/"
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Image {
id: bug
anchors.fill: parent
width: 32
height: 32
source: "qrc:/Original_bug.png"
ShaderEffectSource{
id: shader
sourceItem: bug
width: 128
height: 128
anchors{
right: parent.right
rightMargin: 32
verticalCenter: parent.verticalCenter
}
sourceRect: Qt.rect(x,y, width, height)
}
GaussianBlur {
anchors.fill: shader
source: shader
radius: 8
samples: 4
}
}
}
Using sourceRect property you can specify an area to be blurred.
There are some issues when resizing the source image. This example works good only for static one.

SystemTrayIcon in QML

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.

QML Button exclusiveGroup property?

I'm unable to assign ExclusiveGroup to my checkable buttons.
ExclusiveGroup {
id: group
onCurrentChanged: {
if(current != null) {
console.info("button checked...no!")
current = null
//current.checked = false <--- also this
}
}
}
Column {
width: parent.width
spacing: 0
Button {
id: btnScan
flat: true
text: qsTr("But1")
width: parent.width
checkable: true
exclusiveGroup: group
}
Button {
id: btnWhiteList
flat: true
text: qsTr("But2")
width: parent.width
checkable: true
exclusiveGroup: group
}
}
The documentation states clearly that Button does have exclusiveGroup property http://doc.qt.io/qt-5/qml-qtquick-controls-button.html#exclusiveGroup-prop. However, when I run the example, I get this error:
qrc:/main.qml:48 Cannot assign to non-existent property "exclusiveGroup"
Hovering mouse over "exclusiveGroup" makes a tooltip show up saying: "Invalid property name exclusiveGroup".
I have Qt 5.9.1 installed. Here's my import statements:
import QtQuick 2.7
import QtQuick.Controls 1.4
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
import QtQuick.Controls.Material 2.2
What am I doing wrong?
Thanks
The reason for your problem is this:
import QtQuick.Controls 1.4
import QtQuick.Controls 2.0
You have a Button in both, but they have a different API.
So at first you import the Button from QtQuick.Controls 1.4. Then you import the Button from QtQuick.Controls 2.0. As QML doesn't know, which one you want to use, it will take the one, you imported the last. If you want to be more specific, on which Button you want to use, you can use named imports
import QtQuick.Controls 1.4 as OldCtrl
import QtQuick.Controls 2.0 as NewCtrl
Then you can use Buttons from both versions as you like:
OldCtrl.Button { // from the QtQuick.Controls 1.4 }
NewCtrl.Button { // from the QtQuick.Controls 2.0 }
The documentation you quote is for QtQuick.Controls 1.x, and from there is the imported ExclusiveGroup. So you are trying to mix things from two libraries, that wont work together.
See ButtonGroup for a similar solution for QtQuick.Controls 2.x
For more on the differences and usecases of the both sets of controls read:
http://blog.qt.io/blog/2016/06/10/qt-quick-controls-2-0-a-new-beginning/
https://doc.qt.io/qt-5/qtquickcontrols2-differences.html

Cannot find Qt QML SpinBox minimumValue using QtQuick.Controls 2.1

I got this piece of code:
import QtQuick 2.7
import QtQuick.Controls 1.5
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("spinbox trouble")
SpinBox{
anchors.centerIn: parent
value: 5
minimumValue: 1
maximumValue: 10
}
}
Everything is fine. Now I want to use SwipeView. To use it I need use QtQuick.Controls 2.1. But when I use version 2.1, I cannot find [minimum/maximum]Value in SpinBox.
Questions:
1. What is reason to drop this properties in QtQuick.Controls 2.1?
2. Is there any way to use both SwipeView and SpinBox with [minimum/maximum]Value property?
Looking at the Qt doc I'd say you can use the from and to properties instead of minimumValue and maximumValue!?

Resources