Qt: Make transparent QGraphicsItem objects obscure each other - qt

I would like to add several QGraphicsItem objects to a scene and have them all be transparent (i.e. visible but not completely opaque) with respect to another QPixmapItem background image which is also part of the scene yet obscure each other.
At the moment I am not sure whether this is possible it all. Making all objects in question children of some other QGraphicsItem and then making the parent transparent does not have the desired effect so I guess I'm looking for some completely different approach but I have no idea where to start on this.
EDIT: It seems my explanation was not quite clear enough, I will try to add an example in a few hours time.

From what I understood, you wish to have QGraphicItems which have an opacity less than 100% so that the background image is visible.
To achieve the same, you can use the set opacity function.

Related

How to use common background node for many scenes in Cocos2d-x

I have a very simple problem, but can't seem to find a definite answer.
I'm making a game that uses the same static background in every single scene.
Currently I simply added the background everywhere, but it sort of seems unnatural, makes some of scene transitions I want really painful to make and eventually I'd like to make an animated background which wouldn't reload with every scene change.
Is there a way to add the same node as a background of all the nodes other than creating a singleton which I'd need to add/remove during every transition?
In other words, can the scenes have transparent background so I can push them over the background scene?
I know that CCScene doesn't have setOpacity and have seen that some guys advice using CCLayer for scenes, but then CCDirector::pushScene accepts CCScene as the argument.
EDIT.
Ok, now I see that I probably misunderstood the CCLayer solution.. does it mean that the only way of doing it is to change scenes to layers and then adding/removing them from the main scene?
If you one animating/static background and want everything else to change, i would suggest having using only 1 cocos2d-x Scene with your fancy background and all other layers (previously scene) and elements to this scene.
So, technically you would never ever have to transition from a screen .
But, if you find another solution somewhere, do post/share.

Creating a permanent static overlay for QGraphicsView scene

I am making an app using Qt (currently 4.8) which displays a literal map from a large number of QGraphicsScene items. I would like to annotate the view with a scale. My requirement for the scale is that it is permanently fixed w.r.t the viewport widget. It needs to be updated whenever the view scale changes (zoom in, etc). There are other possible overlay items as well (compass, etc) so I'd prefer a generic solution.
I have looked at earlier questions around this which suggest:
using the ItemIgnoresTransform
using an overlay pixmap.
I tried IgnoresTransform but that way didn't work right: I couldn't figure out how to fix it in place in (say) the bottom corner of the viewport and was having some difficulty getting the text and lines always displaying in the correct size.
I scrapped that and subclassed QGraphicsView, adding an overlay pixmap by reimplementing the paintEvent (calls original one, then paints the overlay pixmap on top), and an alignment option to indicate where it goes. Coding some pixmap paint code produces a usable scale on the view. Yay! ... but it doesn't work with scrolls - I get "shattered" renderings of the scale all over, or sometimes no scale at all. I think this is because QGraphicsView::scrollViewportBy() uses viewport()->scroll() so I wondered if switching to ViewportSmartUpdate would help, but it doesn't help enough. I'd prefer not to switch to ViewportFullUpdate as that would likely slow the app down too much (there are millions of items in the scene and that would require a full repaint just to move around).
So. Any ideas from here? Would adapting my pixmap code to write to a new mostly-transparent Widget that is overlaid on the viewport be a better way?
Thanks for any help...
Though it may not be the best way of doing this, in the past I've added custom widgets to the window that holds the QGraphicsView / QGraphicsScene, which have the same graphic style as the QGraphicObjects in the scene. When the view is then used to move objects in the scene, or the scene itself, the items on the window remain in the same place.
Hope that helps.

Is there a way to use CSS -transform and not affect children elements

I created a mockup to demonstrate my problem. I fear the solution falls in what I did with the first example (box1).
Just not sure why I can't apply a css transform to a parent element and avoid applying it to the child element or at least override it.
Let me know if there is a way to get the effect of the first example using the transform property. I don't want the second image to be scaled as well. Just the parent div.
Note
I'm trying to use this property to enable GPU acceleration.
Have not played with this in any other browser but the chrome.
But it looks like overflow hidden set on parent element implies resizing inheritance on image.
So if you set overflow auto on the boxes to which animation is applied, it should fix the resizing inheritance.
http://jsfiddle.net/gnrlbzik/5Q8EC/ tests the overflow set to auto, that keeps image dimensions in tact.
To be semantic I don't think you should be able to stop it from transforming a child element being you are transforming/scaling it's container, not resizing it. A transform is not just animating the width like the example on box 1, it scales the x.
I believe this question is about trying to gain some performance boost by using features that use the GPU to process animations. This is possible, I believe, by effectively treating the elements as an image that the GPU then animates. Thus you are not able to have an element inside that dynamically keeps its size/shape during an animation. Maybe there is a way to counter the animation by transforming the element within that you would like to keep static, but this will probably not be efficient nor effective.
Note: I am not well versed in the actual technology webkit uses to render these transformations. So sorry if the finer details of the rendering are not quite accurate. I will update this if anyone comments with a better description of how transform works.
I wanted to use -transform to get the GPU performance perk. I guess I'll continue to use the width animation: http://jsfiddle.net/Vyaf3/22/ but with applying a css3 property that would enable the GPU acceleration.

Flex Spark TitleWindow bad redraw on dragging

I have a problem with redrawing in flex 4. I have a spark titleWindow, and if i drag it faster, it looks like it's mask is one frame late after the component.
it's easily visible with 1pixel thin border, because it becomes invisible even with slower movement.
You can try it here (what is not my page, but it's easier to show you here than uploading example):
http://flexponential.com/2010/01/10/resizable-titlewindow-in-flex-4/
If you move in direction up, you see disappearing top border. in another directions it's not that sensitive as it has wide shadow, and it's not very visible on shadow.
On my computer i see it on every spark TitleWindow i have found on google, although it's much less visible with less contrast skins, without borders or with shadows.
Do you see it there? i had never this problem with halo components. It's doing the same thing with different skins. I tried to delete masks from skin, cache component, skin even an application as bitmap with no success.
I also turned on redraw regions in flash player, and it looks like it's one frame late after titlewindow too.
Does anyone know why is it doing this or how can i prevent it?
Thank you
UPDATE:
no answers? really?
I have been facing the same problem and I was really pissed that I couldn't find any answer.
The problem with me was, that I tried to center the component "component.x = (parent.width - component.width) / 2" and then draw that component programatically. The problem was, that component.x is a Number which can lead to floating values like 10.5 or similar. And it looks like that bitmapFill function rounds floats DIFFERENTLY than drawRect function, which makes exactly the 1px line around the objects (but ONLY when parent.width is an odd number). Strange thing for me was, that I only called the Draw function once, but still this line keep recurring ...
Doing Math.floor(component.x) solved the issue.
P.S.: I think that you can also help your issue by setting cacheAsbitmap=true on the dragged object ...
Cheers,
Jan Prazma

Why do DragOver/Enter events require a background on Canvas?

I have a canvas which I want to accept drags on.
I have added a dragOver and dragEnter event listeners to the canvas, but they only work if I drag over something inside the canvas (another child element).
I realised that if I set the canvas' background colour to black it works. So I have set it's background transparency to 0, which works... buy is there a better way to work around this apparent need for the canvas to have something inside it to accept dragEvents.
Thanks
Rob
According to one of the Flex developers, "In Flash there is a difference between a transparent pixel and an area in a Sprite that hasn't been drawn on at all." (http://www.mail-archive.com/flexcoders#yahoogroups.com/msg127690.html)
I'm guessing this is the reason why you need to have the transparent background. For what it's worth, this is always the way I've seen this problem solved. There is also this question which talks about this problem.
Hope this helps!

Resources