Forums

OverviewFelgo 2 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.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support