Finding A Child Control Based On X & Y Coordinate in ActionScript - apache-flex

In Flex/Actionscript
When writing an on mouseMove event on a Canvas control for example, how could I check to see what control if any is under the mouse pointer at a particular coordinate?

You can call getObjectsUnderPoint on your Canvas to determine what children of that canvas are under the current mouse point. You have to make sure the point you pass in is in stage coordinates. Hope that helps.

Related

What does hot spot in Qt drag-and-drop mean?

Qt has a method QDrag::setHotSpot() which
sets the position of the hot spot relative to the top-left
corner of the pixmap used to the point specified by hotspot.
But what is hot spot and its function? How would you define it?
We also specify the cursor's hot spot, its position relative to the
top-level corner of the drag pixmap, to be the point we calculated
above. This makes the process of dragging the label feel more natural
because the cursor always points to the same place on the label during
the drag operation.
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->setPixmap(*child->pixmap());
drag->setHotSpot(hotSpot);
child->hide();
Fridge Magnets Example
The hotspot basically defines where the dragged pixmap shall be located while the drag operation is on-going.
Have a look at this drag & drop example to see how it is typically used.

Shadow Effects with QGraphicsRectItem in Qt

I have a QGraphicsRectItem over a scene. I intend to drag and drop this window over the scene. When the rect item reaches the left boundary end I have to show it appearing from the right end. Currently I am using two objects and hiding and showing them by calculating the boundary of scene which involves lot of calculations.
Is there any better way to achieve the same effect using just a single object?
Thank You
You could use a single item that spans the entire scene, and draw the rectangle (or 2 parts of it) in it's paint method.
But then you would lose the optimization of the BSP tree, your item would redraw even if some unrelated area repaints. If this is just 1 item, I guess it would not have much impact.
You would need to implement your own dragging with mousemove event and the like, though this is not much code, you just need to get it right.

QGraphicsItem - Follow the mouse cursor

I'm stuck on how to approach this. I have a QGraphicsItem within a scene, and I'm passing a hover event from the scene to this child. While the move event occurs (I'm just using mouseMoveEvent with mouse tracking on), I want another QGraphicsItem to follow the cursor.
I don't need any collision detection, drag and drop, etc. Just an item that follows the cursor. The only two ways I can think of are...
While the mouse moves, draw a new QGraphicsItem at the mouse position. I would need to clear the scene, redraw everything, and draw the new position on top.
Somehow use the animation framework and whenever the mouse moves, animate the QGraphicsItem to move to the new mouse position in 1 millisecond.
I'm probably either overthinking this or unaware of another way to do this... any suggestions?
I did it like this
Create the GraphicsItem cursor which will be moved with mouse-cursor, and store its pointer somewhere (in scene subclass for instance. I have a toolset, so for me it's in one of these tools)
Set its Z-Value (QGraphicsItem::setZValue) so that the cursor will be painted above all other items in your scene
Track QGraphicsScene::mouseMoveEvent events, forward these events down to the cursor pointer, and update item's position
that's it.
I guess it corresponds to your solution 1, except you don't have to clear the scene thanks to z-value feature.

QT pixel position from image when mouse click

I'm using QGraphicView and QGraphicScene to display and image. I would like to get image pixel coordinate when i mouse click on that pixel. For that i use mousePressEvent and implement function to isplay event position. But the problem is the image pixel position is wrong because i obtain the pixel coordinate corresponding to the GraphicView not the pixel coordinate in the image. I think it will gives me a right answer when the view have exactly the same size than the image (at least how to do that ?), but i preffer more sophisticated solution.
Please help
You override the mouse press event for QGraphicsPixmap item.

Simpliest ancestor for a clickable, hand-drawn component?

I am creating a component that will be a large plus or a large minus. I don't want to use a bitmap because even I can draw this using the Graphics class, but the component must be clickable (the Shape class is not).
It will be part of an item renderer, so I want it to be as light-weight as possible. UIComponent does not seem to sent CLICK messages.
Thanks for any ideas
I would suggest creating a Sprite object and drawing the minus and plus arrows to its graphics object. You'll then have to addEventListener(MouseEvent.CLICK, someFunction); in its constructor or wherever else you'll need it.
You may also want to set cacheAsBitmap to true at that point, so that it's not redrawn every frame.
EDIT: Per #jeremynealbrown you have to use the SpriteAsset class if you are working in Flex, apparently. Very similar, but another 2 levels of abstraction are added.
If you look here:
UIComponent Docs
You will see that UIComponent has InteractiveObject in its inheritance path. InteractiveObject is the class that adds mouse event functionality.
UIComponent will actually dispatch click events. However, if there is no content drawn to the graphics, the UIComponent will have no area that can be clicked. If the plus or minus icon you draw is too small to reliably catch mouse activities, then draw a fully-transparent rectangle to increase the hit area.

Resources