Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 3 Support (Qt 5) › MouseArea inside object from other QML

Tagged: 

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #15527

    Isak

    Hello, i was trying to make reusable objects for my game so i made an Button.qml but now when i try to add an MouseArea in my created custom button it dont work. Am i missing something here about this? Because if i create an rectangle and put an mousearea inside that it works just fine.

    Main.qml

    Button {
            id: playButton
            buttonFrame: ["PlayButtonUp.png"]
            x: 100
            y: 240
            
    
    
    
            MouseArea {
                anchors.fill: parent
                onPressed: {
                    console.log("test")
                }
            }
    
    
    
    
            }

     

    Button.qml

    import Felgo 3.0
    import QtQuick 2.0
    
    EntityBase {
    
        id: button
        entityType: "button"
        property alias buttonFrame: buttonTexture.frameNames
    
    
    
    
        TexturePackerAnimatedSpriteVPlay {
    
            id: buttonTexture
            source: "../assets/PSFSheet.json"
        }
    
    
    
    
    }

     

     

    #15528

    Alex
    Felgo Team

    Hi,

    your Button has no width or height set, so it is 0x0 pixels in size. Your MouseArea fills this Button, so it has no size as well, thus it’s impossible to click it.

    You could simply set the size of the button to the sprite, by using:

    EntitiyBase {
      width: buttonTexture.width
      height: buttonTexture.height
      //... other stuff
    }

    Also since you want a re-usable button, I’d put the MouseArea inside the button and forward the signal, like you can learn in our Getting Started tutorial. I’d highly recommend going through the whole tutorial, I bet it will answer a lot of your upcoming questions 🙂 We also have a video for this tutorial, if you prefer that!

    Cheers,
    Alex

    #15529

    Isak

    Hi Alex,

     

    I thought that the entity already used the width and size of the texture i used. Yup is gonna go through that tutorial=) Thanks for clearing up this for me:)

     

    /Isak

Viewing 3 posts - 1 through 3 (of 3 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded