Animation on QML not showing? - qt

I have 3 pages :
Main.qml : contains topbar.qml and menubar.qml as static and Audio.qml which is loaded dynamiacally.
In would like to animate menubar ( options buttons) but nothing is showing.
Here is the 4 files. It seems that the Z order is not working.
**Topbar.qml**
import QtQuick 2.0
Item {
id:root
width: 736
height: 55
z:100
FontLoader {
id: regular
source: "fonts/DINPro-Regular.otf"
}
Rectangle {
id: rectangle1
anchors.fill: parent
color: "black"
Text {
id: text1
color: "#ffffff"
text: qsTr("18:00")
anchors.top: parent.top
anchors.topMargin: 16
anchors.bottom: parent.bottom
anchors.bottomMargin: 8
anchors.left: parent.left
anchors.leftMargin: 332
anchors.right: parent.right
anchors.rightMargin: 332
font.pixelSize: 24
font.family: regular.name
}
}
}
Main.QML
import QtQuick 2.0
import QtQuick.Window 2.2
import Controllers 1.0
import "Logic.js" as Controller_Js
Window {
visible: true
id: root
width: 800
height: 480
maximumHeight: height
maximumWidth: width
minimumHeight: height
minimumWidth: width
color: "#000000"
Component.onCompleted: {
Controller_Js.setCurrentPage(Controller.homeView)
loader.source = "Home.qml"
console.log("module controllers", Controller.homeView)
}
FontLoader {
id: regular
source: "fonts/DINPro-Regular.otf"
}
FontLoader {
id: medium
source: "fonts/DINPro-Medium.otf"
}
FontLoader {
id: bold
source: "fonts/DINPro-Bold.otf"
}
TopBar {
id: topbar
x:58
y:0
width: 742
height: 55
}
MenuBar {
id: menuBar1
width: 58
height: 480
}
Item{
id: page
x: 64
y:54
width: 736
height: 426
Loader{
id: loader
x: 0
y: 0
width: 736
height: 428
asynchronous: true
}
MenuBar.qml : short example where i call my animation
Item {
id: optionsBut
x: 8
y: 164
width: 48
height: 52
Image {
id: image2
x: 3
y: 0
width: 37
source: "assets/RT-actionbar-sub-menu.png"
}
MouseArea {
id: mousesubmenu
x: -2
y: -15
width: 53
height: 67
onClicked: {
Controller.statesubmenu="ShowSubmenu"
console.log("state submenu",Controller.statesubmenu )
}
}
}
my animation component : Submenu which have 2 states ; show and hide. In debugger it tell me state : "show" but nothing appears in my screen.
Rectangle {
id: root
x: -382
y: 0
width: 318
height: 425
color: "#282827"
border.width: 0
visible: true
z: 2000
state: Controller.statesubmenu
MouseArea {
anchors.fill: paren
onClicked: mouse.accepted = false
}
Rectangle {
id: item1
width: 317
height: 70
color: "#00000000"
Text {
x: 94
y: 18
width: 100
height: 35
color: "#ffffff"
text: qsTr("Sources")
font.pixelSize: 27
font.family: regular.name
}
Rectangle {
width: 317
height: 1
y:70
color: "#40D8D8D8"
}
}
Rectangle {
id: item2
y: 70
width: 317
height: 70
color: "#00000000"
Text {
x: 94
y: 18
width: 122
height: 35
color: "#ffffff"
text: qsTr("Settings")
font.pixelSize: 27
font.family: regular.name
}
Rectangle {
width: 317
height: 1
y:70
color: "#40D8D8D8"
}
}
Rectangle {
id: item3
x: 0
y: 141
width: 317
height: 70
color: "#00000000"
Text {
x: 94
y: 18
color: "#ffffff"
text: qsTr("Audio Effects")
font.pixelSize: 27
font.family: regular.name
}
Rectangle {
width: 317
height: 1
y:70
color: "#40D8D8D8"
}
}
Rectangle {
id: item4
x: 0
y: 212
width: 317
height: 70
color: "#00000000"
Text {
x: 94
y: 18
color: "#ffffff"
text: qsTr("My stations")
font.pixelSize: 27
font.family: regular.name
}
Rectangle {
width: 317
height: 1
y:70
color: "#40D8D8D8"
}
}
states: [
State {
name: "ShowSubmenu"
PropertyChanges {
target: root
x: 0
}
},
State {
name: "HideSubmenu"
PropertyChanges {
target: root
x : -382
z: 100
visible: true
}
}
]
transitions: [
Transition {
NumberAnimation {
property: "x"
easing.type: Easing.InOutQuad
}
}
]
}

I found the mistake: I did not call the submenu in the loaded page that's why nothing was showing.
now it works nice. I just add :
SubMenuAudio{
id:mysub
}
Thanks

Related

QML Keep transition during the x seconds on mousearea Pressed once

I checked the different mouseArea events in the documentation and there is no chance to execute a function while a mouseArea is being pressed once. I want to keep the transition for 5 seconds and after 5 seconds it should out back.
Here is what i'm trying
Rectangle {
id: bottomBar
x: 0
y: 431
width: 800
height: 100
visible: true
color: "#d0e8f5"
radius: 32
border.width: 0
clip: false
MouseArea {
id: mouseArea
anchors.fill: parent
}
states: State {
name: "moved"; when: mouseArea.pressed
PropertyChanges { target: bottomBar; x: 0; y: 411}
}
transitions: Transition {
NumberAnimation { properties: "x,y"; easing.type: Easing.InOutQuad; }
}
}
i want to keep bottomBar on x:0 y:411 for 5 seconds
Thanks to #iam_peter we figured out the solution. I share the solution below. I also added 2 rowlayouts on this bottomBar and wanted to have 4 images with good alignment and i did. Now i want to make this images clickable and bring the ui to another qmls.(i am using stack view for that)
property string initializePage : "MainMenu.qml"
property string lightningPage : "LightningMenu.qml"
property string timerPage : "Timer.qml"
Rectangle {
id: bottomBar
x: 0
y: 431
width: 800
height: 100
visible: true
color: "#d0e8f5"
radius: 32
border.width: 0
clip: false
MouseArea {
id: mouseArea
anchors.fill: parent
onPressed: SequentialAnimation {
PropertyAnimation {
target: bottomBar
property: "y"
to: 411
}
PropertyAnimation {
targets: [bottomRowLeft,bottomRowRight]
property: "opacity"
to: 1
}
PauseAnimation {
duration: 5000
}
PropertyAnimation {
targets: [bottomRowLeft,bottomRowRight]
property: "opacity"
to: 0
}
PropertyAnimation {
target: bottomBar
property: "y"
to: 431
}
}
}
}
RowLayout{
id: bottomRowLeft
anchors {
left: bottomBar.left
bottom: bottomBar.bottom
}
anchors.bottomMargin: 45
anchors.leftMargin: 175
spacing: 10
opacity: 0
//Home Icon
Image{
source: "/images/homeButtonIcon.png"
}
MouseArea{
id: homeClicked
Layout.fillWidth: true
onClicked: {
stackViewTool.replace(Qt.resolvedUrl("MainMenu.qml")) // not working
}
}
Image{
source:"/images/removeButtonIcon.png"
}
MouseArea{
id: removeClicked
Layout.fillWidth: true
}
}
RowLayout{
id: bottomRowRight
anchors {
left: bottomRowLeft.right
bottom: bottomBar.bottom
}
anchors.bottomMargin: 45
anchors.leftMargin: 215
spacing: 10
opacity: 0
//Home Icon
Image{
source: "/images/cancelButtonIcon.png"
}
MouseArea{
id: cancelClicked
Layout.fillWidth: true
}
Image{
source:"/images/applyButtonIcon.png"
}
MouseArea{
id: applyClicked
Layout.fillWidth: true
onClicked: {
stackViewTool.replace(lightningPage)
}
}
}
StackView {
id: stackViewTool
anchors {
left: parent.left
right: parent.right
top: parent.top
bottom: bottomBar.top
}
initialItem: initializePage
}
You want to trigger an animation on MouseArea press, then the property should change, pause and go back to the previous value?
Rectangle {
id: bottomBar
x: 0
y: 431
width: 800
height: 100
visible: true
color: "#d0e8f5"
radius: 32
border.width: 0
clip: false
MouseArea {
id: mouseArea
anchors.fill: parent
onPressed: SequentialAnimation {
PropertyAnimation {
target: bottomBar
property: "y"
to: 411
}
PauseAnimation {
duration: 5000
}
PropertyAnimation {
target: bottomBar
property: "y"
to: 431
}
}
}
}
The issue on your example is that the MouseArea isn't filling the Image you should use anchors.fill and make the MouseArea a child of the Image. Currently it is also layouted by the RowLayout which you might want but doesn't make sense if you want to make the images button-like. I came up with this solution which might be what you want. This is just a guess.
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
Window {
id: root
color: "white"
width: 800
height: 600
visible: true
component SimplePage: Rectangle {
property alias name: pageText.text
width: root.width
height: 200
color: "lightgrey"
Text {
id: pageText
anchors.centerIn: parent
font.pixelSize: 40
}
}
component SimpleButton: Rectangle {
property alias letter: buttonText.text
signal clicked
color: "grey"
width: 40
height: 40
Text {
id: buttonText
anchors.centerIn: parent
font {
pixelSize: 20
bold: true
}
}
MouseArea {
anchors.fill: parent
onClicked: parent.clicked()
}
}
Component {
id: initializePage
SimplePage { name: "initialize" }
}
Component {
id: lightningPage
SimplePage { name: "lightning" }
}
Component {
id: timerPage
SimplePage { name: "timer" }
}
Rectangle {
id: bottomBar
x: 0
y: 431
width: 800
height: 100
visible: true
color: "#d0e8f5"
radius: 32
border.width: 0
clip: false
MouseArea {
id: mouseArea
anchors.fill: parent
onPressed: SequentialAnimation {
PropertyAnimation {
target: bottomBar
property: "y"
to: 411
}
PropertyAnimation {
targets: [bottomRowLeft,bottomRowRight]
property: "opacity"
to: 1
}
PauseAnimation {
duration: 5000
}
PropertyAnimation {
targets: [bottomRowLeft,bottomRowRight]
property: "opacity"
to: 0
}
PropertyAnimation {
target: bottomBar
property: "y"
to: 431
}
}
}
}
RowLayout {
id: bottomRowLeft
anchors {
left: bottomBar.left
bottom: bottomBar.bottom
}
anchors.bottomMargin: 45
anchors.leftMargin: 175
spacing: 10
opacity: 0
// Home
SimpleButton {
letter: "H"
onClicked: stackViewTool.replace(initializePage)
}
// Remove
SimpleButton {
letter: "R"
}
}
RowLayout {
id: bottomRowRight
anchors {
left: bottomRowLeft.right
bottom: bottomBar.bottom
}
anchors.bottomMargin: 45
anchors.leftMargin: 215
spacing: 10
opacity: 0
// Cancel
SimpleButton {
letter: "C"
}
// Apply
SimpleButton {
letter: "A"
onClicked: stackViewTool.replace(lightningPage)
}
}
StackView {
id: stackViewTool
anchors {
left: parent.left
right: parent.right
top: parent.top
bottom: bottomBar.top
}
initialItem: initializePage
}
}
I made the following changes to your example:
Use a Page control
Put the toolbar in the footer section
Use Frame and RowLayout for the toolbar
Refactored AppButton.qml for a clickable icon Button
Supplied mock MainPage.qml and LightningPage.qml
Supply mock SVG assets
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
Page {
StackView {
id: stackView
anchors.fill: parent
initialItem: "MainPage.qml"
}
footer: Frame {
background: Rectangle { color: "#d0e8f5" }
RowLayout {
AppButton {
icon.source: "home-32.svg"
onClicked: stackView.replace("MainPage.qml")
}
AppButton {
icon.source: "x-circle-32.svg"
}
AppButton {
icon.source: "thumbs-up-32.svg"
onClicked: stackView.replace("LightningPage.qml")
}
}
}
}
// MainPage.qml
import QtQuick
import QtQuick.Controls
Page {
Text {
anchors.centerIn: parent
text: qsTr("MainPage.qml")
}
}
// LightningPage.qml
import QtQuick
import QtQuick.Controls
Page {
Text {
anchors.centerIn: parent
text: qsTr("LightningPage.qml")
}
}
// AppButton.qml
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
Button {
Layout.preferredWidth: 64
Layout.preferredHeight: 64
background: Rectangle {
radius: 8
border.color: focused ? pressed ? "white" : "black" : "grey"
color: pressed ? "lightsteelblue" : "#ccc"
}
icon.color: pressed ? "white" : "black"
icon.width: 32
icon.height: 32
}
// home-32.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path d="M11 8.5V5H6v8.5L2.5 17H5v12h8v-8h6v8h8V17h2.5L16 3.5zM26 16v12h-6v-8h-8v8H6V16H4.914L7 13.914V6h3v4.914l6-6L27.086 16z"/><path fill="none" d="M0 0h32v32H0z"/></svg>
// thumbs-up-32.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path d="M29.878 13.966A2.564 2.564 0 0 0 27.422 12h-4.61a12.784 12.784 0 0 1-1.447-.054 4.48 4.48 0 0 1 .078-.083c.063-.051 1.522-1.33 1.522-4.903 0-2.832-.52-4.436-1.591-4.904a2.336 2.336 0 0 0-2.283.577l-.16.148L18.93 3a9.143 9.143 0 0 1-1.608 4.53 12.855 12.855 0 0 1-3.396 3.745L10.78 16H9v-2H3v15h6v-2h2.767l3.363 2h9.664a2.807 2.807 0 0 0 2.534-1.58 2.586 2.586 0 0 0 .069-2.196 2.683 2.683 0 0 0 1.464-1.773 2.773 2.773 0 0 0-.42-2.298 2.873 2.873 0 0 0 1.303-1.938 2.754 2.754 0 0 0-.653-2.22 3.037 3.037 0 0 0 .787-3.03zM8 28H4V15h4zm20.073-11.477l-.582.364.525.442a1.889 1.889 0 0 1 .74 1.73 2.006 2.006 0 0 1-1.299 1.487l-.748.305.605.533a1.786 1.786 0 0 1 .58 1.814 1.725 1.725 0 0 1-1.342 1.261l-.776.167.485.628a1.589 1.589 0 0 1 .17 1.725A1.813 1.813 0 0 1 24.794 28h-9.389l-3.363-2H9v-9h2.32l3.255-4.96a13.852 13.852 0 0 0 3.58-3.957 10.348 10.348 0 0 0 1.764-4.833 1.222 1.222 0 0 1 1.055-.278c.298.13.99.78.99 3.988 0 3.06-1.16 4.135-1.197 4.169-.194.193-.705.706-.483 1.244.25.599 1.037.627 2.528.627h4.61a1.58 1.58 0 0 1 1.495 1.241 1.99 1.99 0 0 1-.844 2.282z"/><path fill="none" d="M0 0h32v32H0z"/></svg>
// x-circle-32.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path d="M22.864 10.843L17.207 16.5l5.657 5.657-.707.707-5.657-5.657-5.657 5.657-.707-.707 5.657-5.657-5.657-5.657.707-.707 5.657 5.657 5.657-5.657zM29.8 16.5A13.3 13.3 0 1 1 16.5 3.2a13.3 13.3 0 0 1 13.3 13.3zm-1 0a12.3 12.3 0 1 0-12.3 12.3 12.314 12.314 0 0 0 12.3-12.3z"/><path fill="none" d="M0 0h32v32H0z"/></svg>
You can Try it Online!

Set correct size for custom QML slider

I'm trying to create a reusable slider. I'm having trouble to set implicit sizes correctly so that the CustomSlider includes the Slider and the Label. I would like to have a implicit size specified, but let the user set a width for the slider itself.
I tried using childrenRect but that gives me a binding loop error.
How can I have the yellow background span across all the components: the slider and the green label?
Currently:
Would like:
CustomSlider.qml
Item {
id: root
property int startval: 0
property int endval: 20
property int sliderWidth: 200
// This results in binding loop
//implicitHeight: childrenRect.height
implicitHeight: control.height + label.height
implicitWidth: sliderWidth
Rectangle {
color: "yellow"
width: root.width
height: root.height
}
Slider {
id: control
stepSize: 1
anchors.centerIn: parent
snapMode: Slider.SnapOnRelease
width: root.sliderWidth
from: root.startval
to: root.endval
handle: Rectangle {
id: handleId
x: control.visualPosition * (control.width - width)
y: (control.height - height) / 2
width: 20
height: 20
radius: 20
color: "gray"
}
background: Rectangle {
y: (control.height - height) / 2
height: 4
radius: 2
color: "green"
Rectangle {
width: control.visualPosition * parent.width
height: parent.height
color: "red"
radius: 2
}
}
}
Label {
id: label
width: 20
height: 20
text: control.value
font.pixelSize: 15
color: "black"
x: handleId.x + control.x
y: handleId.y - 20
Rectangle {
color: "green"
anchors.fill: parent
opacity: 0.3
}
}
}
Main.qml
CustomSlider {
anchors.centerIn: parent
startval: 0
endval: 10
//sliderWidth: 100
}
I usually set the Width and height based on the parent.
I set sliderWidth: parent.width/2.0 and for your green label I add TextMetrics and calculate its width based on the text that it wants to show.
import QtQuick 2.15
import QtQuick.Controls 2.15
Item {
id: root
property int startval: 0
property int endval: 0
property int sliderWidth: parent.width/2.0
// This results in binding loop
//implicitHeight: childrenRect.height
implicitHeight: control.height + label.height
implicitWidth: sliderWidth
Rectangle {
color: "yellow"
width: root.width
height: root.height
}
Slider {
id: control
stepSize: 1
anchors.centerIn: parent
snapMode: Slider.SnapOnRelease
width: root.sliderWidth
from: root.startval
to: root.endval
handle: Rectangle {
id: handleId
x: control.visualPosition * (control.width - width)
y: (control.height - height) / 2
width: 20
height: 20
radius: 20
color: "gray"
}
background: Rectangle {
y: (control.height - height) / 2
height: 4
radius: 2
color: "green"
Rectangle {
width: control.visualPosition * parent.width
height: parent.height
color: "red"
radius: 2
}
}
}
Label {
id: label
width: t_metrics.tightBoundingRect.width +4
height: t_metrics.tightBoundingRect.height +7
text: control.value
font.pixelSize: 15
color: "black"
x: handleId.x + control.x
y: handleId.y - 20
Rectangle {
color: "green"
anchors.fill: parent
opacity: 0.3
}
}
TextMetrics {
id: t_metrics
text: control.value.toString()
}
}
Updated:
in CustomSlider.qml , changed it to this code:
import QtQuick 2.15
import QtQuick.Controls 2.15
Item {
id: root
property int startval: 0
property int endval: 0
property int sliderWidth: parent.width/2.0
implicitHeight: control.height + label.height
implicitWidth: sliderWidth
Rectangle {
color: "yellow"
width: root.width +10
height: root.height +control.height + label.height + t_metrics.tightBoundingRect.height +7
Slider {
id: control
stepSize: 1
anchors.centerIn: parent
snapMode: Slider.SnapOnRelease
width: root.sliderWidth
from: root.startval
to: root.endval
handle: Rectangle {
id: handleId
x: control.visualPosition * (control.width - width)
y: (control.height - height) / 2
width: 20
height: 20
radius: 20
color: "gray"
}
background: Rectangle {
y: (control.height - height) / 2
height: 4
radius: 2
color: "green"
Rectangle {
width: control.visualPosition * parent.width
height: parent.height
color: "red"
radius: 2
}
}
}
Label {
id: label
width: t_metrics.tightBoundingRect.width +4
height: t_metrics.tightBoundingRect.height +7
text: control.value
font.pixelSize: 15
color: "black"
x: handleId.x + control.x
y: handleId.y /2 + 4
Rectangle {
color: "green"
anchors.fill: parent
opacity: 0.3
}
}
TextMetrics {
id: t_metrics
text: control.value.toString()
}
}
}
This makes your text label shows inside the yellow rectangle and in main.qml I add one Row with labels and spinboxes for the test.
If you want that user to set sliderWidth or startval and endval and then show him Slider you need to create that object dynamically.
and if you want to be displayed in the Column and don't overlap you need ColumnLayout.
If you want to scroll them then you need to use ScrollView.
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
Window {
width: 660
height: 480
visible: true
title: qsTr("Hello World")
ScrollView {
width: parent.width
height : parent.height
contentWidth: slidersColumn.width
contentHeight: slidersColumn.height
clip : true
ColumnLayout {
id: slidersColumn
anchors.fill: parent
spacing:50
}
}
function addSlider(sliderWidth,startval,endval) {
var obj = Qt.createComponent("CustomSlider.qml");
var slider = obj.createObject(slidersColumn);
slider.startval=startval;
slider.endval=endval;
slider.sliderWidth=sliderWidth;
}
Row
{
x: 0
y: 5
width: parent.width
height: 30
Label {
id: lbl_slider_width
text: qsTr(" Slider width ")
}
SpinBox {
id: spinBox_slider_width
editable: true
from:0
to:parent.width
}
Label {
id: lbl_startval
text: qsTr(" Startval ")
}
SpinBox {
id: spinBox_startval
editable: true
from:0
to:parent.width
}
Label {
id: lbl_endval
text: qsTr(" Endval ")
}
SpinBox {
id: spinBox_endval
editable: true
from:0
to:parent.width
}
Button {
id: button
text: qsTr(" Create Slider")
onClicked:
{
addSlider(spinBox_slider_width.value,spinBox_startval.value,spinBox_endval.value)
}
}
}
}
The result is:

ListView cannot load delegate from another qml file

i want to use ListViewDelegate.qml as a delegate for my list view items on my Kos.qml. but it giving me this error. i also try using loader but it seems didn't work, i try to remove the curly braces and it load the Kos.qml page but it didn't render the list view
file:/ngomahyukv2/Kos.qml:55: ListViewDelegate is not a type
File name case mismatch
#Kos.qml
i use another file PageBackground.qml as a background
import QtQuick 2.4
import QtQuick.Controls 2.3
PageBackground {
id: kos
width: 640
height: 480
Text {
id: element
x: 6
y: 20
width: 24
height: 32
color: "#ffffff"
text: qsTr("<")
font.strikeout: false
styleColor: "#ffffff"
font.underline: false
font.italic: false
font.bold: true
font.pixelSize: 25
MouseArea {
id: mouseArea
anchors.rightMargin: 0
anchors.bottomMargin: 0
anchors.leftMargin: 0
anchors.topMargin: 0
anchors.fill: parent
onClicked: kosloader.source = ""
}
}
ListView {
id: listView
x: 0
y: 69
width: 640
height: 410
model: ListModel{
// need to be in for loop and data from database
ListElement{
imagePath : "static/Bisnis-kos-kosan.png"
kosName : "Kos Name"
kosAlamat : "Jalan Lorem"
kosJumlahKamar: "5"
kosGender : "Laki-laki"
kosHarga: "7000000"
kosProfile: "KosSpec.qml"
ownerContact: "instgram.com"
}
}
delegate: ListViewDelegate { }
}
Loader{
id: kosspec
visible: false
source: ""
}
}
#ListViewDelegate.qml
import QtQuick 2.0
import QtQuick.Controls 2.13
Item {
id: listviewdelegate
Image {
id: idthumbnail
x: 8
y: 8
width: 227
height: 158
source: imagePath
fillMode: Image.PreserveAspectCrop
}
Text {
id: idnamakos
x: 252
y: 8
text: kosName
font.bold: true
font.family: "Verdana"
wrapMode: Text.WordWrap
font.pixelSize: 22
}
Text {
id: idalamat
x: 251
y: 40
width: 301
height: 17
text: qsTr("Alamat : " + kosAlamat)
wrapMode: Text.WordWrap
font.pixelSize: 12
font.family: "Verdana"
}
Text {
id: idjumlahkamar
x: 252
y: 63
width: 240
height: 14
text: qsTr("Jumlah Kamar : " + kosJumlahKamar)
wrapMode: Text.WordWrap
font.pixelSize: 12
font.family: "Verdana"
}
Text {
id: idgender
x: 251
y: 83
width: 265
height: 14
text: qsTr("Gender : " + kosGender)
wrapMode: Text.WordWrap
font.pixelSize: 12
font.family: "Verdana"
}
Text {
id: idharga
x: 251
y: 103
width: 373
height: 14
text: qsTr("Harga : " + kosHarga)
wrapMode: Text.WordWrap
font.pixelSize: 12
elide: Text.ElideNone
font.family: "Verdana"
}
Button {
id: buttonCek
x: 510
y: 131
width: 96
height: 35
visible: true
font.family: "Verdana"
font.pixelSize: 16
background: Rectangle{
color: "#ef3644"
anchors.fill: parent
}
contentItem: Text {
id: cek
text: "CEK"
anchors.fill: parent
verticalAlignment: Text.AlignVCenter
font.bold: true
font.pointSize: 10
horizontalAlignment: Text.AlignHCenter
color: "#ffffff"
}
MouseArea {
id: mouseAreaCek
anchors.fill: parent
onClicked: {
kosspec.visible = true
kosspec.source = kosProfile
}
}
}
Button {
id: buttonHubungi
x: 400
y: 131
width: 96
height: 35
font.family: "Verdana"
visible: true
contentItem: Text {
id: name1
color: "#ef3644"
text: "HUBUNGI"
anchors.fill: parent
font.bold: true
font.pointSize: 10
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
}
background: Rectangle {
color: "#00f1f0f0"
border.width: 4
border.color: "#ef3644"
anchors.fill: parent
}
font.pixelSize: 16
MouseArea {
id: mouseAreaHubungi
anchors.fill: parent
onClicked: {
Qt.openUrlExternally (ownerContact);
}
}
}
ToolSeparator {
id: toolSeparator
x: 5
y: 172
width: 600
height: 15
orientation: Qt.Horizontal
}
}
As the error message says, it seems to have to do with the casing of your file. Custom types need to begin with a capital letter, but also check that you have got the V and D in the correct case.
Also, is the file in the same directory? Do you have files named the same but with different casing in parallel? Directories?
I'm pretty confident that the issue is in the file name, or the name of a file that interferes with the file name. However, if you want to create a type module and refer to the file that way, you can also poke at using qmldir files: https://doc.qt.io/qt-5/qtqml-modules-qmldir.html .
But try to find something odd in your files first.

How to set Layout.alignment multiple times?

How in Rowlayout or ColumnLayout center an element and keep them in order so no matter how scaled the first object the second will always be after it.
ColumnLayout {
id: currentMusicRow
anchors.horizontalCenterOffset: wrapper.width / -4.5
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.topMargin: 20
Rectangle {
id: currentPicBackground
x: 273
y: 20
width: 260
height: 260
color: "#151515"
Layout.alignment: parent.AlignHCenter
Image {
id: currentMusicPic
x: 2
y: 2
anchors.fill: parent
anchors.margins: 2
source: "images/maxresdefault.jpg"
fillMode: Image.Stretch
}
}
RowLayout {
id: titleMusicLayout
width: 222
height: 29
Layout.horizontalCenter: parent.AlignCenter
Layout.bottomMargin: -50
Layout.bottom: currentPicBackground.AlignBottom
Text {
id: band
width: 155
height: 28
color: "#f2f2f2"
text: qsTr("Glad Boris")
font.italic: false
font.weight: Font.Medium
style: Text.Normal
font.underline: false
font.family: "Acme"
font.bold: false
font.pixelSize: 22
MouseArea {
id: bandMouseArea
width: 123
height: 28
anchors.centerIn: parent
hoverEnabled: true
}
}
Text {
id: diveder
width: 13
height: 28
color: "#f2f2f2"
text: "/"
font.bold: false
font.pixelSize: 22
font.family: "Tahoma"
}
Text {
id: musicName
width: 103
height: 28
color: "#f2f2f2"
text: "relaxation"
font.weight: Font.Light
font.bold: false
font.pixelSize: 20
font.family: "Acme"
MouseArea {
id: musicNameMouseArea
width: 103
height: 28
anchors.centerIn: parent
hoverEnabled: true
}
}
It shows an error because I set alignment multiple times but I need somehow to keep my texts(inside RowLayout) lower than my rectangle/image(inside ColumnLayout) EVEN IF THE IMAGE IS SCALED UP MORE (The texts have to be fixed to the bottom of it).

QML: How to select radio button from listview?

I have next listview component:
CustomListRadio.qml
import QtQuick 2.12
import QtQuick.Controls 2.12
import "."
Rectangle {
id: radio_content
x: 0
y: 40
width: 320
height: 158
color: "black"
property int counter: 0
property int savedIndex: 0
property int checkedIndex: 0
property variant internalModel
ButtonGroup {
id: buttonGroup
}
ListView {
id: list
x: 0
y: 0
width: 320
height: 158
model: parent.internalModel
anchors.fill: radio_content
delegate: RadioDelegate {
text: modelData
checked: index == radio_content.savedIndex
ButtonGroup.group: buttonGroup
font.pixelSize: 23
font.family: "Futura Condensed"
font.styleName: "Medium"
MouseArea {
anchors.fill: parent
onClicked: {
parent.checked = true
radio_content.checkedIndex = model.index
}
}
}
}
}
RadioDelegate.qml
import QtQuick 2.12
import QtQuick.Controls 2.12
RadioDelegate {
id: control
text: qsTr("RadioDelegate")
checked: true
contentItem: Text {
leftPadding: control.indicator.width + control.spacing
text: control.text
font: control.font
opacity: enabled ? 1.0 : 0.3
color: "white"
elide: Text.ElideRight
verticalAlignment: Text.AlignVCenter
}
indicator: Rectangle {
implicitWidth: 30
implicitHeight: 30
x: control.leftPadding
y: parent.height / 2 - height / 2
radius: 15
color: control.checked ? "#0088FF" : "white"
border.color: "#0088FF"
Rectangle {
width: 10
height: 10
x: parent.width / 2 - width / 2
y: parent.height / 2 - height / 2
radius: 5
color: "white"
visible: control.checked
}
}
background: Rectangle {
implicitWidth: 320
implicitHeight: 40
color: "black"
border {
color: "#383838"
width: 1
}
}
}
How add component
CustomListRadio {
id: radio_list
internalModel: msg.languageVariantList
savedIndex: msg.language
}
It creates a list of radiobuttons. It works well. But, I can't select default checked radio button. Selecting a switch with the mouse, works. But from the code, at best, my solution selects the switch only if the length of the list is equal to the number of visible elements.
Problem in RadioDelegate.qml, need to remove next string:
checked: true

Resources