[Android-development] Fwd: Nine-Patch Images

Filip Piechocki fpiechocki at gmail.com
Fri Mar 22 08:39:43 CET 2013

Thanks for your advice! I used this approach but it seems to not be working
well. The thing You didn't mention is that we need to cut out the 1 pixel
border from the original image. I did it by setting BorderImage's
anchors.margins to -1 and settings it's parent clip to true. But it works
only if the BorderImage's smooth is set to false, otherwise the black lines
from the "meta-data" 9 patch image border is sometimes visible - it appears
that it might spread on more then 1 pixel while scaling despite it
shouldn't be scaled. But setting smooth to false makes the bitmap look

So my conclusion is that it should be done in BorderImage C++
implemantation, or we need to write our own item implemented in C++.

Best regards,
Filip Piechocki

On Tue, Mar 19, 2013 at 12:31 PM, Eskil Abrahamsen Blomfeldt <
eskil.abrahamsen-blomfeldt at digia.com> wrote:

>  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
> _______________________________________________
> Android-development mailing list
> Android-development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/android-development
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/android-development/attachments/20130322/83e527d2/attachment.html>

More information about the Android-development mailing list