[Solved] How to use qml to display a specified part of a picture



  • could anyone tall me how to do this in qml? Just like background-position in CSS.



  • Can you explain a bit more? You want to display a piture in some position on the screen or you want to display some part of image?

    Taka a look at "Image.fillMode":http://doc.qt.nokia.com/4.7-snapshot/qml-image.html#fillMode-prop



  • Hmmm, not sure of any built in way of doing this. You may need to write your own custom item in C++ and expose this to the QML context. It should be relatively simple to do.



  • I want to display some part of a image, and I guess the only way to do it is pointed out by ZapB~ Thank u for replying!

    [quote author="task_struct" date="1317632528"]Can you explain a bit more? You want to display a piture in some position on the screen or you want to display some part of image?

    Taka a look at "Image.fillMode":http://doc.qt.nokia.com/4.7-snapshot/qml-image.html#fillMode-prop[/quote]



  • hi guys, I solved this in this way!
    @
    Rectangle{
    id: login
    clip: true
    width: 80
    height: 25
    Image {
    id: loginButton
    x: 80
    y: 0
    source: "./image/Login_btn_login.png"
    }
    }
    @
    Put an image in a rectangle change x and y of the image, until get the right part of the image! Cheers!

    Edit: Be sure and wrap code in @ tags; mlong



  • I`ve just wrote similar example :)



  • Hi,

    Glad you found a solution for this. Note that using an Item to do the clip, rather than a Rectangle, may be slightly more efficient (a Rectangle will try to paint itself, while an Item won't).

    Regards,
    Michael


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.