I'm sketching a UI in Scene Builder and was a bit surprised about the layout behaviors.
In XCode I'm used to define distance constraints so that widgets will stick to a side of a given container and won't overlap each other when window is resized.
In SB it seems that I have to wrap widgets in HBOXes before I can glue them to a corner in a parent Anchor container. Is that correct or am I missing something?
Also, I'd like to maintain a fixed distance between widgets but HBOX doesn't seem to provide one by default.
Is there a layout manager that provides "springy" distance minimums like Qt or Apple?
TIA,
Eddy
Related
I have a window in mono gtk#, which has lot of VBoxes & HBoxes. These boxes contain some buttons, labels, and some other widgets also. Now I need to make this window alone to transparent.
I created one drawingArea by referring zetcode page.
But inside this drawing area I'm not able to do the arrangements of my widgets, one Move function is available, but it is not much use for me. So how do I do widget arrangement neatly inside a drawingArea?
I want to build a game and therefore I would like to create a game menu. This menu should be in front of the scene, but not totally hide it, somehow sticking at the lens of the camera. My first idea was to create planes as buttons and position them at the same position as the nearplane and move it with the camera.
Is there also a easier way to do this?
(I also saw this, but I don't know how to do it without qml)
The way games make HUDs or menus is by (I think) using orthographic projection which makes it unnecessary to have them at the near-plane (and gets rid of some side effects). I didn't find anything nicer than this to describe orthographic projections.
So to implement this you would have two framegraph branches:
Draw your objects as normal
Draw your menu using orthographic projection
The elements of the menu could be planes like you said. You can add QObjectPickers to the planes and then react to the clicks.
I have implemented an example for the opposite thing: I created a framegraph that draws a background image behind the 3D scene. It needs adjusting for rescaling the window but should give you the general idea. You can find the project here.
(This is a related question regarding how to put normal Qt widgets like QPushButton in a Qt3D window.)
I'm trying to understand (in general terms) the difference between a javafx 2 Scene and Pane. I can get them to work, but I haven't found a clear explanation of what functionality each provides.
The javadoc api defines a Scene as "the container for all content in a scene graph". A Pane (subclass of Region, Parent, Node) is also a container (since widgets like Button) get added to it, rather than to Scene. Apparently Pane handles layout and Scene does not.
Or to put it another way: widgets get added to Panes, a Pane is attached to a Scene, and a Scene is attached to the top level container, Stage. Since Pane does layout and can have properties set such as size, css style, etc., what functionality does the Scene provide? It does appear to be required.
Thanks
what functionality does the Scene provide?
Why don't you just compare the Javadoc of both?
E.g.
Scene is not a Node
Scene has a camera and a window property
...
So you have only one Scene per Stage but possibly several Panes (a Pane is-a Node).
The Scene is the start of, well, the scence graph. But it is more light-weight than a Stage/ Windows, AFAIK.
Scene class is the container for all content in a scene graph While Pane Class is subclass of Scene Class.
In Scene u can set element(Pane) using (SceneObject).setroot() method while In pane u can set element(Node) using (Pane Object).getchildren.add(element(Node)Object).
I'm pretty new to javafx so I'm trying to learn here so please be reasonable and don't dis away my question, I really appreciate any help at all, thanks!
I would like to know how I could move an object, let's say this circle on different events, like keypress or mouseclick, mousemove, whatever.
Circle circle = new Circle();
circle.setCenterX(100.0f);
circle.setCenterY(100.0f);
circle.setRadius(50.0f);
Do I need to use that KeyFrame thing I saw on the javafx site tutorial, or how does this work?
I would not have asked this here if I weren't feeling so lost, honestly.
So to make this clear: What is the code for moving objects that I created, by using events?
EDIT: By moving it I mean, press up key and it moves up by a few pixels, transform it maybe, with another key, or click somewhere on the scene and make it move there instantly or travel there with a certain speed. I don't have to redraw it like you need to with html5 canvas, I hope, right?
I don't have to redraw it like you need to with html5 canvas, I hope, right?
Not if you are using a standard JavaFX scene graph as opposed to a JavaFX canvas.
I would like to know how I could move an object, let's say this circle on different events, like keypress or mouseclick, mousemove, whatever
There are three ways to move a Shape:
You can adjust the shape's geometry (e.g. the centerX/centerY properties of a circle).
You can adjust the shape's layout (e.g. it's layoutX/layoutY properties).
You can adjust the shape's translation (e.g. it's translateX/translateY properties).
You can think of the layout as the home position for the object; i.e. where it should normally be in the context of it's parent group. You can think of it's translation transform as a temporary position for an object (often used when the object is being animated).
If you are using a layout pane such as a VBox or TilePane, then the layout pane will handle setting the layout co-ordinates of the child node for you. If you are using a simple Group or a plain Pane or Region, then you are responsible for setting the correct layout values for the child nodes.
To listen for events, set event handlers on Nodes or Scenes.
Here is a small sample app which demonstrates the above. It places the object to be moved inside a Group and modifies the position of the object within a Group in response to various events.
I ran in to a problem where I was doing property animations on widgets but they animation positions would seem to get overwritten on the next layout pass. The widgets would seem to jump position right at the beginning of animation, making it look bad. As a result I thought maybe if I wrote my own layout code I could have more control over things.
What is the easiest way to write a custom layout in QT? I tried following the steps in the "Manual Layout" section of the documentation: http://doc.qt.nokia.com/latest/layout.html#manual-layout However I seem to be hitting a crash when I try calling setGeometry on the child widgets. Also, the docs seem to conflict with the "Manual Layout" saying to call setGeometry from within resizeEvent and the resizeEvent doc saying not to do that.
I suppose I could just write a real layout class. Doesn't look like too much code. But I'm wondering what the easiest/simplest way to get custom layout is.
I think this might work.
Start with widget A positioned entirely outside of the parent widget. Do not add that widget to the layout. A's geometry may well share an edge with the parent.
Create a dummy widget D that forwards A's sizeHint() but does nothing else. Put it into the layout.
Animate widget A toward the geometry of widget D.
Swap the widgets in the layout (remove widget D, add widget A).
If widgets A and D are of your own making, then you should be using the PIMPL idiom. If your widget has no child widgets, swapping the widgets would be trivial -- swap the pimpl pointers. The widgets themselves don't have to be swapped then. DO NOT derive your PIMPL class from QWidgetPrivate, not that it's supported anyway, but I've seen code that does it. Not a good idea.