09-20-2012 09:49 AM
Hi,
I want to set an image as a background to the label.Please provide me the solution.I am able to set the background image for a conatainer using imagePaintDefintion in attachedProperty.But i am unable to set an image as a background to the label.please provide me the solution.
Regards,
NareshKodumuri.
09-20-2012 10:32 AM
Hello,
Please Find attachement.
Thanks.
--------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
09-20-2012 10:41 AM
There is no method to provide background to a Label.
Well as you said you can set image as background to a container.
Then do the same whatever you were doing, only add one more step:
Put your label inside a container(parent to label) with its preferredwidth and preferredheight property equal to that of label.
Also set label's layoutproperties: property with
horizontalAlignment: HorizontalAlignment.Fill verticalAlignment: VerticalAlignment.Fill
That will be all for a pseudoLabel with image set as its background.
Well you can also monitor the opacity of the image by setting opacity: property of parent container.
A sample
Container {
id: labelParent
layout: DockLayout {
}
background: paint.imagePaint
opacity: 0.5
attachedObjects: [
ImagePaintDefinition {
id: paint
imageSource: "asset:///images/mybackground.png"
repeatPattern: RepeatPattern.XY
}
]
layoutProperties: StackLayoutProperties {
verticalAlignment: VerticalAlignment.Center
horizontalAlignment: HorizontalAlignment.Center
}
Label {
id: labelID
objectName: "myLabel"
text: "text"
layoutProperties: DockLayoutProperties {
horizontalAlignment: HorizontalAlignment.Fill
verticalAlignment: VerticalAlignment.Fill
}
}
}
Ok . I know the solution is weird but as long as we don't have any method to set image as background of a label, we can use this trick.
Hope it helps