[Android-development] Fwd: Nine-Patch Images

Eskil Abrahamsen Blomfeldt eskil.abrahamsen-blomfeldt at digia.com
Tue Mar 19 12:31:00 CET 2013


On 03/19/2013 11:20 AM, Filip Piechocki wrote:
> Yes, I thought about some boolean property in BorderImage (let's say 
> "ninePatch") so when set to true then the BorderImage will read 
> borders from the image file (the black stripes in the file output from 
> draw9patch) and as a source use and 1 pixel each side shrunk image. I 
> think that the 9-patch image format is on one hand something 
> Android-like but on the other - it can be used anyware. So I think it 
> would be nice to have it directly in QtDeclarative, but I wrote here, 
> as I thought here is the greatest chance that someone already 
> considered this. As I need such a functionality then I am looking for 
> the best solution - I can make my own Item but it would be quite time 
> consuming and duplicating BorderImage once again, as the original 
> implementation is "private". So I thought about extending BorderImage, 
> but the C++ code is private and uses internal classes so I thought it 
> would be nice to get some advice how to make it nice (for now I have 
> it almost working) so then maybe push the merge request to Qt repo.

I think for Qt in general it's probably better to have a editor that 
integrates with QML and sets the margins on the item. Having attributes 
stored in external files doesn't fit very well with how QML is designed 
otherwise, so this is mainly a feature needed for support of the Android 
tools.

For inheriting an item in QML, just do something like this (in a file 
called e.g. MyBorderImage.qml) (this is just pseudo-code of course):

Item {
     property string source: ""

     onSourceChanged: {
         var borderImageData = readDataFrom(source)
         borderImage.border.left = borderImageData.left
        // etc.
     }

     BorderImage {
         id: borderImage
         anchors.fill: parent
     }
}

So you implement readDataFrom() to read from the file and then set the 
margins on the item. You then instantiate MyBorderImage in your QML file 
and set its "source" property to use it.

-- Eskil

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/android-development/attachments/20130319/9a2548b6/attachment.html>


More information about the Android-development mailing list