Sharing a VBO across multiple QWidgets in JOGL - qt

I'm trying to share create four QGLWidgets with the same GL3 context so I can share a VBO between them. I've been doing this for a while with just one widget, but it wasn't shared with the others. QGLWidget has a sharewith paremeter, which from what I understand automatically shares the contexts between them, but I'm not sure how compatible that is with JOGL.
I'm also confused about when the context is actually created. In some examples it says to create the context in initializeGL. I'm not sure if that means I have to update the first widget before I can create the secondary widgets (passing the sharewith paremeter the first created widget with a current context).
Can anyone provide me with a simple example to get this functioning? I just need to create four context-sharing GLWidgets that all run off a GL3 profile.

Although I'm not using JOGL, I am doing a similar thing here and here. The basic idea is that you create a hidden QGLWidget, make it current and compile all your shaders, then pass it as the shareWidget to your child viewports. Whenever you want to upload geometry
make the hidden QGLWidget current and do your glBufferData calls - the data becomes available to the other viewport contexts.

Related

Qt Quick Dynamically Custom Layouts (like workspaces in an IDE)

The project I'm working on calls for workspace layouts for a large section of it, by which I mean that users can move around panes, resize them, close them, etc., like in VSCode (but more like Emacs since VSCode does not currently support both vertical and horizontal splitting).
The current methodology I'm considering to create a custom LayoutManager that has a json object and injects views into recursive Row and Column objects in a binary-tree-like structure. Before I start this undertaking, I'm wondering if there is a library or set of QtQuick (QML) elements that would let me do this a lot more easily or if there is a better approach to this problem. Or, please just tell me why I'm wrong in doing it this way.
Note: The technologies I'm using are C++ with Qt 5 (currently 5.10).
If you want highly customizable GUI, with the option of persisting UI configuration, it is best to design the whole thing model driven.
QML already has the necessary stuff - list views, repeaters and so on. QML is a little at odds with tree models, but you can essentially fake a tree by using lists of lists.
The model provided here will do the trick, with the added benefit it also supports declarative instantiation. So you can easily set up an initial GUI state declaratively, like you would with normal QML, but then allow the user to make modifications to that initial state which can then be saved and recalled.
Then all you have to do is bind the desired GUI elements to the underlying model data source objects.

Extend a class to have my custom class rendered as part of the Node graph?

In JavaFX, once I have a Scene, Pane, and/or Canvas setup and have my Node graph setup, how do I add my own custom components? I've already added them to the Node graph, but they're not being rendered, because they neither inherit from a particular node nor implement the particular method necessary to have their rendering method called. There isn't much complexity involved in drawing these components -- it's about twenty calls of drawRectangle etc..
If I recall correctly, in Swing, I had each component implement a version of draw, and draw was called automatically as part of the framework. But I haven't found the equivalent mechanism in JavaFX yet.
JavaFX doesn't have "ondraw" in the usual sense, because components are usually composed and rendered on GPU.
There are multiple ways to create custom drawing, depending on your needs and requirements.
You can merely use Canvas for simple drawing, pretty clear described in official tutorial . This is the simplest way for complex drawings and probably it is what you are looking for. Add canvas node to the scene and draw on it. You can encapsulate the logic by extending Canvas or a container component that will contain Canvas (or by presenter etc. if you employ some kind of MVP/MVC).
Another way is just to compose from existing visual components e.g. shapes and images, for example by extending or preparing a Pane or other container and adding children components.
Yet another is to prepare a bitmap with custom drawing and use Image component, you can use Swing or other APIs to draw a bitmap in advance and use it for rendering. In general this is similar to using canvas but more complex, unless you see clear benefits or have particular reasons, canvas is preferred.
Last way is to implement custom scene Node with complete rendering, I would not go into detail and advice against it; it is relatively complex, will use non-public APIs, probably would not be compatible between JDK releases and is useful only for very special needs.
Note, if you are creating a custom reusable library component, you probably will need to dive into the topic of skinning and component lifecycle.
I needed to pass in the Pane that I'm using for drawing into the constructor of my "custom class." The custom class then adds the necessary shapes to the provided pane. I assume I'll also need to keep track of those shapes as a data member of the custom class and remove/replace them when the custom class needs a new visual representation.
See Fedor Losev's answer below for a more complete list of options. E.g., I could have used a Canvas instead of a Pane.

Best Qt Widget to use for flow controls

I want a widget that can have various number of input & output pins, and each instance of this widget acts as a module which can connect to another module via these pins. Eventually, this will give me a work flow with many connected blocks. Ideally, the connection can be done via mouse operations such as drag and drop from one pin to another. And I also need to add texts or even draw some shapes onto the blocks.
I know that I can write this from scratch but what's the best base widget to start with?
I would go with QGraphicsItem. It supports features like drag & drop, collision detection, etc.. Those should be useful for your use-case. Make sure to check other classes that inherits this one (look for Inherited By:).
Also, make sure to check out this article.

Select layout by user in QML application

In my QML application there are many components like map, video, console and so on. I want to allow the user to change current layout of components (position and visibility). The problem is that I want each layout to be separate .qml file which reuse already existing components. For example on layout switch map should not be destroyed and instantiated again. Here is an example of what I would like to avoid - each layout creates components only for themselves so layout cannot be changed. I had some experiments with reparenting components on state change but it produces a lot of code and nothing works.
Looks like you need to use states! Each state can arrange same items in different layout. They can even re-parent items.
Now question is: can you move state description to separate file. IMO it should work. I didn't try it.
Anyway items will not be recreated so you will achieve main goal.

Qt: using one widget in several layouts

I have a QTabBar, and all tabs are supposed to have the same widget in them:
layout1->addWidget(w);
layout2->addWidget(w);
However calling addWidget the second time causes this widget to disappear in the first layout.
Is there any way to use one widget to insert it in several tabs?
Of course I can always create a new widget instance for every tab, but that takes extra time and memory.
Is there any way to use one widget to insert it in several tabs?
No. If you want the widget to be seen twice, then you need two instances of it.
Of course I can always create a new widget instance for every tab, but that takes extra time and memory.
Simple widgets are relatively cheap in regards to memory/time to create. Unless your GUI is becoming unresponsive and your profiler says that this is a problem, you are likely attempting a premature optimization.
Depending on the specific goal you're trying to accomplish, there are patterns such as using multiple views that share a single model that can potentially be employed.

Resources