QML Image scale unexpected behavior - qml

Qt 5.9.2
The following QML code:
ApplicationWindow
{
visible: true
width: 585
height: 113
title: qsTr("test")
Rectangle
{
width: 585
height: 113
color: "black"
x: 0
y: 0
}
Image
{
source: "balloon.png"
x: 0
y: 0
}
}
produces the expected result:
When I add scale: 0.5 to Image element, I get this:
But I expected it to look like this:
Can somebody please explain me why 0.5 scaled image is not located at (0,0) coordinates as it explicitly set in its properties and can something be done here for the scaled image to be located at (0,0) coordinates?

As mentioned in the documentation for scale, scaling is applied from the transformOrigin, and the default origin is Item.Center, so you need to specify Item.TopLeft:
import QtQuick 2.7
import QtQuick.Controls 2.0
ApplicationWindow {
visible: true
width: 585
height: 113
title: qsTr("test")
Rectangle {
width: 585
height: 113
color: "black"
x: 0
y: 0
}
Image {
source: "balloon.png"
x: 0
y: 0
scale: 0.5
transformOrigin: Item.TopLeft
}
}
The x and y properties only affect an item's position, not its scaling origins. Note that there's also the transform property if you need to do more advanced transformations.

Related

How do I get the frame of visible content from SKCropNode?

It appears that, in SpriteKit, when I use a mask in a SKCropNode to hide some content, it fails to change the frame calculated by calculateAccumulatedFrame. I'm wondering if there's any way to calculate the visible frame.
A quick example:
import SpriteKit
let par = SKCropNode()
let bigShape = SKShapeNode(rect: CGRect(x: 0, y: 0, width: 100, height: 100))
bigShape.fillColor = UIColor.redColor()
bigShape.strokeColor = UIColor.clearColor()
par.addChild(bigShape)
let smallShape = SKShapeNode(rect: CGRect(x: 0, y: 0, width: 20, height: 20))
smallShape.fillColor = UIColor.greenColor()
smallShape.strokeColor = UIColor.clearColor()
par.maskNode = smallShape
par.calculateAccumulatedFrame() // returns (x=0, y=0, width=100, height=100)
I expected par.calculateAccumulatedFrame() to return (x=0, y=0, width=20, height=20) based on the crop node mask.
I thought maybe I could code the function myself as an extension that basically reimplements calculateAccumulatedFrame with support for checking for SKCropNodes and their masks, but it occurred to me that I would need to consider the alpha of that mask to determine if there's actual content that grows the frame. Sounds difficult.
Is there an easy way to calculate this?

Single word per line in kivy(GridLayout)

I'm trying to make a app similar a menu. I already did scrollview with gridLayout, but I don't know how to show this separate, for instance, in the left column names, and in the right column age, in this way the app may have variable number of rows (infinity). I hope I have been less confusing as possible, the same for my english. Thanks everybody, I didn't post my code here because I think it isn't necessary. Bye, have a good day.
Ass is important I post my code here, I'm going to try to post. I'm sorry for the mistakes like indent.
.py
class PrimeiroScreen(Screen):
def __init__(self, **kwargs):
self.name = 'home'
super(Screen,self).__init__(**kwargs)
class SegundoScreen(Screen):
text = StringProperty('')
def __init__(self, **kwargs):
self.name = 'dois'
super(Screen,self).__init__(**kwargs)
class RootScreen(ScreenManager):
pass
class scrollmanageApp(App):
def build(self):
return RootScreen()
if __name__ == '__main__':
appVar = scrollmanageApp()
scrollmanageApp().run()
.kv
<RootScreen>:
PrimeiroScreen:
SegundoScreen:
<PrimeiroScreen>:
BoxLayout:
size_hint: (.3,.15)
pos_hint:{'x': .35, 'y': .84}
Label:
text: "Teste de uniĆ£o scrollview com screenmanage"
font_size: '30dp'
GridLayout:
cols: 1
rows: 2
size_hint: (.20,.10)
pos_hint:{'x': .25, 'y': .64}
Button:
text: "Scrollview!"
font_size: '30dp'
text_size: self.size
on_press: root.manager.current = 'dois'
<SegundoScreen>:
text: 'This is just a test ' * 50
ScrollView:
size_hint: 1, 1
pos_hint:{'x': .0, 'y': .0}
size: 100, 100
GridLayout:
cols: 2
#rows:
padding: 10
spacing: 10
size_hint: None, None
width: 500
height: self.minimum_height
Label:
text: root.text
font_size: 50
text_size: self.width, None
size_hint_y: None
height: self.texture_size[1]
Button:
text: "Voltar!"
size_hint: .1, .1
pos_hint:{'x': .9, 'y': .0}
text_size: self.width, None
on_press: root.manager.current = 'home'
I hope I had sucess in this time(post my code).Very thanks!

Xcode UILabel upside down

I want to have a label which should be displayed upside down. That means after creating the label I want to turn it around 90 degrees. That works but now the label is anywhere. I don't know HOW the label is rotated. Maybe one could help me. The code is the following:
let label = CreatorClass.createLabelWithFrame(CGRect(x: 10, y: 10, width: 150, height: 15), text: "aString", size: 12.0, bold: false, textAlignment: .Left, textColor: UIColor.whiteColor(), addToView: self)
label.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))
CreatorClass creates a label and add it to a certain view (it adds to self because this code is called in a subclass of UIView). Actually it's self-explanatory I think.
you label rotate around its center, that means:
You label rotate around : x = 10 + 75 = 85
y = 10 + 7.5 = 17.5
This is also the center of the new position, what has a width of 15.0 and height of 150;
The new rect of your view, after the transfer is:
x = 85 - 7.5 = 77.5;
y = 17.5 - 75 = -57.5;
width = 15 , height = 150.
It could be out of the self bounds.
You might want to go back your label to its init position, only need to put it to init position:
label.frame = CGRect(x: 10, y: 10, width: 15, height: 150)

Dojox chart number of Y axis labels

When I create a DojoX vertical bar chart, it automatically calculates the labels on the Y axis to cover the largest value. In this case, it created 3 Y-axis labels, 100, 200 300.
How do I increase the number of labels, to say intervals of 50 rather than intervals of 100?
When you add an axis, there are several options you can use for the tick marks. Example:
chart.addAxis("y", {
majorTicks : true, // default
majorLabels : true, // default
majorTick : {length: 4, color: "#FFF"},
majorTickStep : 10,
minorTicks : true,
minorLabels : true,
minorTick : { length: 2, color: "#CCC"},
minorTickStep : 5,
...
vertical: true
});
Check the API docs for more: http://dojotoolkit.org/api/1.8/dojox/charting/axis2d/Default

Mouseevent when near an Element with Raphael

According to this question
Raphael - event when mouse near element
i create a invisible rectangle around another rectangle ,
when the mouse is over that large rect, a circle will appear.
but because the large rect is on top of the small rect,
i can't process another event when mouse is over the small rect.
(if the small rect is on top , the point will disappear when i reach the small rect)
And i want also to have another event with the circle.
Is there any solution for this?
Hier is the code
Kind of mimicking the events of the larger rectangle with the smaller one:
var paper = new Raphael(0, 0, 500, 500);
createRect(100, 100, 100, 50);
function createRect(x, y, width, height) {
var boundrect = paper.rect(x - 30, y - 30, width + 60, height + 60).attr({
"fill": "pink",
"stroke": "none"
}).mouseover(function(event) {
topCtrl.show()
}).mouseout(function(event) {
topCtrl.hide()
})
,
rect = paper.rect(x, y, width, height).attr({
"fill": "white",
"stroke": "red"
}).mouseover(function(event) {
topCtrl.show();
topCtrl.attr({
"fill": "white"
})
}),
topCtrl = paper.circle(x + (width / 2), y, 5).attr({
"fill": "red"
});
}