10-30-2012 04:36 PM
It is sometimes required to retrieve the size of a control (a button, a label ... etc).
I have struggled find a property or method that would allow me to read the current control size.
Is it possible at all?
Thanks.
Solved! Go to Solution.
10-30-2012 04:43 PM
10-30-2012 04:48 PM
Thanks, but this is a handler for changes in the layout (position, size ...). If the size and position do not change - how does one get that information?
10-30-2012 05:29 PM
10-30-2012 07:51 PM
That is understood, but the problem arises with a situation like this
bb::cascades::ImageView* anImageView = new bb::cascades::ImageView();
anImageView->setImageSource(QUrl("asset///someimag
Loading an image like this will set the ImageView size to the size of the image by default. At this point I would like to know the size of "anImage" control. I understand that I could have connected the layout events to the object before I assigned the image source, but then I have to manage and keep that information somewhere. What if I have 10, 20, 100 of these little images. I would have to create a wrapper object or a new one inheriting from the ImageView just so I can connect the events and store the information somewhere so I can use it on demand.
That information must be available somewhere. I can't believe that there is no access to it. If there isn't - it's really a missing piece.
QImage has information about the image size. Casscade's Image (accessible through the ImageView as well) doesn't.
10-30-2012 08:24 PM
10-31-2012 09:37 AM
Yes - I am aware of the ImageData - thanks. The problem is when one wants to use the AbsolluteLayout and layout other controls based on the sizes and positions of other controls.
I used the ImageView control because that was the easiest to demonstrate the issue with.
translationX() property is also being changed by the layout of the controls, yet it is accessible on demand. I do not understand why there is no property called "currentSize" for example.
We'll find some workaround, but this is definitely a shortcoming - particularly when one uses the AbsoluteLayout.
10-31-2012 10:50 AM
Since we need for a particular subset of custom made controls, we decided to use the LayoutUpdateHandler after all.
If anyone has needs for similar functionality - here how we did it.
Our control(s) have a private QRectF currentBounds; member.
In the control's constructor we added the following
LayoutUpdateHandler::create(this).onLayoutFrameChanged(this, SLOT(onLayoutFrameChanged(QRectF)));
Then implemented a private slot onLayoutFrameChanged(QRectF& bounds) and update the private currentBounds member.
It's not pretty and, most importantly, should not be really needed in our opinion, but it works and we can always access the "currentBounds" property to get the actual bounds.