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.
Related
I am using QT Designer to create a dynamic view for a certain component in my application. However, the 'apple' and 'Food:' text items within the RowLayout aren't aligned properly. I am trying to make it so that the baseline of those texts are aligned. I'm not sure how I can do that.
Note: I could set a custom margin just for the apple, but I would like to avoid that as I want my layout to be as dynamic as possible for different screen sizes/resolutions
import QtQuick 2.0
import QtQuick.Controls.Material 2.12
import QtQuick.Layouts 1.12
Item {
id: item1
width: 500
height: 300
x: 177
y: 258
Rectangle {
id: container
anchors.centerIn: parent
anchors.fill: parent
color: "black"
anchors.left: parent.left
anchors.right: parent.right
ColumnLayout{
anchors.left: parent.left
anchors.top: parent.top
anchors.leftMargin: 16
anchors.topMargin: 16
spacing: 0
Text {
id: category
x: 194
y: 227
width: 92
color: "#FFFFFF"
text: qsTr("Category")
font.pixelSize: 18
font.family: "Roboto Medium"
}
RowLayout{
spacing: 2
Text {
id: categoryTitle
width: 365
height: 10
color: "#FFFFFF"
text: qsTr("Food: ")
font.pixelSize: 60
verticalAlignment: Text.AlignBottom
Layout.alignment: Qt.AlignLeft | Qt.AlignBottom
font.family: "Roboto"
}
Text {
id: categoryItem
height: 62
width: 365
color: "#FFFFFF"
text: qsTr("apples")
font.pixelSize: 30
verticalAlignment: Text.AlignBottom
Layout.alignment: Qt.AlignLeft | Qt.AlignBottom
font.family: "Roboto"
}
}
}
}
}
What it looks like right now:
Instead of:
Layout.alignment: Qt.AlignLeft | Qt.AlignBottom
use
Layout.alignment: Qt.AlignLeft | Qt.AlignBaseline
I have two QML pages main.qml and Kos.qml,
what i want is when a button in main.qml clicked it load Kos.qml in the screen.
i did try using loader, but it is not working
import QtQuick 2.5
import QtQuick.Controls 2.5
ApplicationWindow {
id: applicationWindow
width: 640
height: 480
color: "#fc4343"
title: qsTr("Tabs")
visible: true
// HALAMAN UTAMA
Page {
anchors.centerIn: parent
anchors.fill: parent
id: page
enabled: true
Loader{
id: kos
active: true
anchors.fill: parent
}
Button {
id: button
x: 198
width: 87
height: 30
text: qsTr("Search")
font.bold: true
anchors.top: borderImage.bottom
anchors.topMargin: 198
anchors.right: toolSeparator.left
anchors.rightMargin: 28
MouseArea{
anchors.fill: parent
onClicked:{
kos.source = "Kos.qml";
}
}
background: Rectangle {
id: background
color: "#ef3644"
}
contentItem: Text {
id: textItem
font: control.font
opacity: enabled ? 1.0 : 0.3
color: "white"
text: "Search"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
}
}
Kos.qml i use PageBackground as a background
import QtQuick 2.4
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
}
}
}
did i messed up somewhere?
I tried to run your code. Since I am not aware of what your PageBackground is, I changed that to Rectangle. That works for me. Try to start from the minimal code then add your styles and functions on top of it. Try with below minimal code. Keep both main.qml & Kos.qml in the same directory and ensure both files added to qml resources.
main.qml
import QtQuick 2.9
import QtQuick.Controls 2.2
ApplicationWindow {
id: applicationWindow
width: 640
height: 480
visible: true
Text {
anchors.centerIn: parent
text: "App window"
}
Loader {
id: loaderId
anchors.fill: parent
source: ""
}
Button {
text: "click me!!"
width: parent.width
anchors.bottom: parent.bottom
onClicked: {
if(loaderId.source == "")
loaderId.source = "Kos.qml"
else
loaderId.source = ""
}
}
}
Kos.qml
import QtQuick 2.9
Rectangle {
id: kos
width: 640
height: 480
color: "grey"
Text {
anchors.centerIn: parent
text: "<b>Loaded Item</b>"
color: "white"
}
}
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).
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
Hi all I have tried several things but I can't make my ListView to response to mouse click.
Here is my code of ListView:
ListView {
id: listview1
x: 0
y: 82
// width: 574
// height: 967
width: window.width
height: window.height
visible: true
keyNavigationWraps: false
boundsBehavior: Flickable.DragAndOvershootBounds
opacity: 1
maximumFlickVelocity: 2500
anchors.leftMargin: 0
highlightMoveSpeed: 489
contentWidth: 0
preferredHighlightEnd: 2
spacing: 5
highlightRangeMode: ListView.NoHighlightRange
snapMode: ListView.SnapToItem
anchors.bottomMargin: 0
anchors.rightMargin: 0
anchors.topMargin: 82
anchors.fill: parent
model: myModel
delegate:Component {
//id: contactDelegate
Item {
property variant myData: model
width: 574; height: 90
Column {
x: 12
y: 0
width: 562
height: 90
anchors.rightMargin: 0
anchors.bottomMargin: 0
anchors.leftMargin: 12
anchors.topMargin: 0
anchors.fill: parent
spacing: 2
Text { text: '<b>ID: </b> ' + id_korisnika ; verticalAlignment: Text.AlignTop; wrapMode: Text.NoWrap; horizontalAlignment: Text.AlignHCenter; color:"steelblue"; font.family: "Helvetica"; font.pointSize: 10 }
Text { text: '<b>Ime: </b> ' + ime_korisnika ; horizontalAlignment: Text.AlignHCenter; color:"steelblue"; font.family: "Helvetica"; font.pointSize: 10 }
Text { text: '<b>Prezime: </b> ' + prezime_korisnika; horizontalAlignment: Text.AlignHCenter; color:"steelblue"; font.family: "Helvetica"; font.pointSize: 10 }
Text { height: 16; text: '<b>Broj telefona: </b> ' + broj_korisnika ; verticalAlignment: Text.AlignVCenter; horizontalAlignment: Text.AlignHCenter; color:"steelblue"; font.family: "Helvetica"; font.pointSize: 10 }
Text { text: '<b>Adresa: </b> ' + adresa_korisnika ; horizontalAlignment: Text.AlignHCenter; color:"steelblue"; font.family: "Helvetica"; font.pointSize: 10 }
MouseArea {
id: mouse_area1
z: 1
hoverEnabled: false
anchors.fill: parent
}
}
}
}
//delegate: contactDelegate
highlight: Rectangle {color:"black"; radius: 5; opacity: 0.7
}
focus: true
}
I have tried to put my code in all areeas but I can't make it work. any suggestion is nice.
See KeyInterction sample from QtCreator. There is your answer :)
You can see sample delegate as follow:
ListViewDelegate:
Item {
id: container
width: ListView.view.width; height: 60; anchors.leftMargin: 10; anchors.rightMargin: 10
Rectangle {
id: content
anchors.centerIn: parent; width: container.width - 40; height: container.height - 10
color: "transparent"
antialiasing: true
radius: 10
Rectangle { anchors.fill: parent; anchors.margins: 3; color: "#91AA9D"; antialiasing: true; radius: 8 }
}
Text {
id: label
anchors.centerIn: content
text: "List element " + (index + 1)
color: "#193441"
font.pixelSize: 14
}
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
onClicked: {
container.ListView.view.currentIndex = index
container.forceActiveFocus()
}
}
}
The key is MouseArea section.
Good luck - S.M.Mousavi
i dont see onClicked handler code in your MouseArea (mouse_area1). How are you trying to capture/respond the mouse click.
Try following code and see what happens.
MouseArea {
id: mouse_area1
z: 1
hoverEnabled: false
anchors.fill: parent
onClicked:{
console.log("test");
}
}