Render Order of Transparent Mesh on Unity3D UI canvas - unity3d-2dtools

I have a procedural mesh of a 2D circle attached to a ScreenSpace-Camera UI canvas and I want to render some UI text on top of it. However the UI text is always rendered below the circle despite me sorting their z-order. If I change to material to some opaque material, everything works fine. So how do I handle the transparent render order for mesh objects that are treated as a UI element

Try changing the UI Canvas 'Order in Layer' = 1

As a best practice I think you should have one camera only for UI rendering and another for the scene.

Related

Transparency on only one side

I was trying to add some transparency to a text and oddly enough I noticed it was only transparent on one side while being opaque on the other.
The expected behavior was transparent on both sides. Any idea why this happens?
Thank you.
https://aframe.io/docs/0.8.0/components/material.html#transparency-issues
With opacity, A-Frame sets three.js renderer to sortObjects: false. Transparency ordering is based on when objects are added / defined in the scene. Shuffle the order of the text in like the HTML or when they are injected and it should work.

JavaFX: Rectangle with custom bounding rect and paint method

What I want to do:
In PySide, one could override the paintEvent() method of a QWidget to draw a custom widget. The bounding rect can be customized by overriding the boundingRect() method.
How does one do this in JavaFX? My goal is to create a custom Rectangle object, that draws itself smaller than it's bounding rect.
In context:
I'm creating an MS Paint clone in JavaFX. I'm working on the selection box that you use to select/move pixels around. I want the cursor to change to the appropriate resizing cursor when it is near the outside of the selection box.
However, the bounding rect is the same size as the selection box drawn on the screen, so the cursor only changes when it is on top of the box, but not when near. My solution is to set the bounding rect to larger than the actual selection box is, so the cursor change will occur. Then, override it's paintEvent() equivalent to draw a smaller selection box.
Thanks for your help.
I have a similar use case to you, and asked a similiar question here : Drawing transform independent layout bounds in JavaFX.
The JavaFX API is much higher level though than Java2D or PySide (I am assuming from your snippets, because I actually never heard of it ;) ), it does not allow you to override painting of Nodes, nor can you stop a Node from inheriting its parents transform.
This means that you need a seperate Group parallel to your content where you create the selection box and update it according to your needs (content changes etc.).
Example SceneGraph:
Scene
contentGroup
someShapeFromUser
selectionBoxGroup
selectionBoxOfSomeShapeFromUser

Qt 4.7.4 - Make transparent pixels clickable (expand hitbox) in QGraphicsItem pixmap

I am creating a circuit schematic editor using Qt Creator. I have a QGraphicsScene/QGraphicsView canvas that I would like to drop images of circuit components onto and move them around.
I am currently using a pixmap QGraphicsItem and adding it to the canvas and making it movable. This works great when you click directly on the symbol's lines, however the symbol does not move when the transparent areas in the image are clicked.
Is there a way to expand the hitbox/mouse area to make these transparent regions respond the same as the other regions do on the symbol? Below is how I am adding the image. (I need the image transparent so that other symbols are visible behind/infront of it)
QGraphicsItem* b = canvas.addPixmap(QPixmap(":/images/ground2.gif"));
b->setFlag(QGraphicsItem::ItemIsMovable);
b->setPos(qrand()%int(canvas.width()),qrand()%int(canvas.height()));
All help is much appreciated! Thanks!
Josh
You can call QGraphicsPixmapItem::setShapeMode( QGraphicsPixmapItem::BoundingRectShape ) to have the item treated a rectangle.

Semi-transparent QWidget over QGLWidget: Strange results

I have a full size QGLWidget which paints the application background using QPainter (might change to native openGL commands in the future).
On top of this QGLWidget I use QWidgets (non-GL) for the user interface elements. These are, for example, QLineEdits and QPushButtons. I put them into a custom painted QWidget which uses semi-transparent background painting. The paintEvents of the QLineEdit and QPushButton are overwritten and use semi-transparent backgrounds, too.
The whole UI should look like the following (This is a screenshot where I disabled OpenGL and used QWidget instead of QGLWidget for the background. Note the semi-transparent top bar which also draws a shadow (within its own region)):
When the QLineEdit has the focus, it should have a higher opacity but still not fully opaque:
So now, with OpenGL enabled (The background then is a QGLWidget), the semi-transparent widgets above don't paint on top of the background but on (it seems to be) uninitialized data. The image shining through the top bar is sometimes the whole window itself and sometimes other windows currently being on my desktop.
This currently looks like the following (In this screenshot, the data on which the semi-transparent painting operations are painted on seems to be an image of the widget itself, having an offset.):
When I wrote text into the line edit (here: "This is some text which has been there before!"), removed it and set the focus back to the background widget (so the magnifier icon and the placeholder text appear), the previously painted things still shine through (Note that the visible border should not be visible anymore, but also still shines through):
So the problem is: Instead of being painted on top of the underlying widgets, the semi-transparent widget is painted on top of the old results, initially being something like "uninitialized memory".
Why does this happen? How can I solve the problem?
Things you should know before answering:
The background scene is a composition of tiles which are rendered off-screen. So it can be painted very fast and repainting of the background for every little change of the overlay isn't problematic.
The top bar is a custom QWidget with manual painting and arrangement of the contained two widgets (the button and line edit).
The two widgets overwrite the paintEvent, only draw their own (semi-transparent) background when they have focus and don't use frames already provided by Qt. So the white border in the second screenshot is drawn in my custom paintEvent.
I want the background and the composition of overlay widgets to be separately implementable. The background is an AbstractMapView which has some concrete map view classes. The whole window is an AbstractView (there are multiple concrete views, too), which contains both a concrete map view and the overlay widgets, composed in a way itself decides. Therefore, I don't want the logic of the overlay widgets to be part of the underlying map view. (I hope you understood this, as it is a bit complicated.)
This sounds like an issue where the GL content (i.e. your background aka the QGLWidget) is not in the Qt context. While I'm not a pro on GL painting with Qt, you may want to look at this discussion regarding GL painting and a QLabel for some direction/potential hints.
http://www.qtcentre.org/threads/40335-QLabel-on-top-of-a-QGLWidget-background-issue
In short, we here at the office use OpenGL painting and offscreen rendering of maps and it's very important to make sure Qt is aware of the pixels so your foreground widgets can have the semi-transparency applied to their backgrounds.
The particular product we use also renders the map in tiles and supports providing the GL output in a buffer (i.e. it's call a snapshot and is provided as a bitmap) at which point we use the paintEvent of a regular QWidget to paint the buffer so that the painted pixels are in Qt context.
You can define a Qframe with Qt::SplashScreen flag as the search box and set its opacity. Put your widgets inside it such as the search textbox and positon it where it should appear on the mainwindow. It will also be a good idea to reposition it as the mainwindow is moved or resized overriding its moveEvent.

How to make Widgets background transparent in Qt

I am building an App in which I had given background to my mainWindow only and all other widgets are used without any background, but when I run the app they are not 100% transparent they are somewhat translucent, is there any way to make them 100 % transparent so that only foreground can appear with no background hint.
Could you post the code you are using to get transparancy at the moment? If you say that you get "something translucent" I think that you created a tool window which is not what you really want.
A really transparent main window could be achieved by removing the title bar (give the QWidget constructor Qt::FramelessWindowHint as second parameter - WindowFlags), draw everything in the widget that should be transparent in a uncommon color (like 255,0,255) and then cut it off.
A very primitive example of cutting off parts of a QWidget:
QBitmap b(100, 100);
b.fill(Qt::black);
setMask(b);
QBitmap must be black on that pixels that shall be visible and white on that are not. In this example just the 100,100 area starting at 0,0 will be visible, the rest of your window will be invisible.

Resources