Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Image proportional growth in QML

Image proportional growth in QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 309 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hello, I am developing a flower watering application. The application works as follows. When a seed presses the current water button, this seed changes the picture and goes to the next form.

    import QtQuick 2.15
    import QtQuick.Window 2.15
    import QtQuick.Controls 2.15
    import QtQuick.Layouts 1.15
    
    ApplicationWindow {
        id: rootWindow
    
        visible: true
        visibility: Window.FullScreen
    
        property real dp: Screen.pixelDensity * 10 * 2.54 / 160
    
        property int val: 0
    
        Image {
            fillMode: Image.PreserveAspectCrop
            source: "qrc:/assets/images/bg.png"
            anchors.fill: parent
        }
    
        ColumnLayout {
            anchors.fill: parent
            spacing: 0
    
    
            Rectangle {
                Layout.preferredHeight: 50 * dp
                Layout.preferredWidth: 50 * dp
                Layout.topMargin: 50
                Layout.alignment: Qt.AlignHCenter
                color: "red"
                radius: 100
    
                Label {
                    anchors.centerIn: parent
                    color: "#ffffff"
                    text: "Water"
                }
    
                MouseArea {
                    anchors.fill: parent
                    onClicked: {
                        flowerImage.width = flowerImage.width * 2
                        flowerImage.height = flowerImage.height * 2
                        rootWindow.val =  rootWindow.val + 1
    
                    }
                }
    
            }
    
            Item {
                Layout.fillHeight: true
            }
    
    
            Image {
                id: flowerImage
    
                Layout.preferredHeight: 50 * dp
                Layout.preferredWidth: 50 * dp
                Layout.alignment: Qt.AlignCenter
                Layout.bottomMargin: 90
    
                fillMode: Image.PreserveAspectFit
                source: {
                    if(rootWindow.val === 0) {
                        return "qrc:/assets/images/seed.png"
                    }
                    if(rootWindow.val === 1) {
                        return "qrc:/assets/images/seed1.png"
                    }
                    if(rootWindow.val === 2) {
                        return "qrc:/assets/images/seed2.png"
                    }
                    if(rootWindow.val === 3) {
                        return "qrc:/assets/images/seed3.png"
                    }
                }
    
            }
        }
    }
    
    

    This is how it looks when I run the code.

    22485842-34ad-4ea5-89f6-e40fc1560fe6-image.png

    If we click the water button I expect the seed image to change and grow but that doesn't work. The picture changes and eventually the picture grows.

    c6af2966-06b9-4e13-9264-7b1ce6004b26-image.png

    79b1673c-263c-496c-aecb-b985fe511d56-image.png

    bf1468c0-ebe9-4ee0-925f-5525c66bdc06-image.png

    I want the seeds to grow as they are watered and move on to the next form. How can I do this properly?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved