I need to create a GUI with a file menu and menu in which the user can input parameters. The parameters are then used for drawing rectangles in a canvas which is part of the application window. Is there a way to scale the OpenGL subwindow to just one part of the screen and the parameter input to the other? The application needs to be written in C++.
Is it possible to create a GUI with QT and draw the rectangles in the same window using OpenGL? If not, what is the common way to integrate a GUI with OpenGL? (or any other graphics library which I can use to draw rectangles from points as easy as possible)
EDIT: I am not sure If OpenGL is necessary or there is a way to paint the rectangles on the canvas like you can in Java with paintComponent().
I have never used QT before so I am not aware of its capabilites.
you can use opengl window singly or use this in the common mainwindow. previous example (in first answer) show how to use opengl window in qt singly and without communication with other components of Qt (like menu, toolbar and ...). but you can add a opengl window to a mainwindow (like other widget) and use it alongside other widgets . this example can help you.
Yes, using OpenGL together with Qt is absolutely possible. There is even an example for that and Qt provides classes for a more object oriented way of using OpenGL. Have a look here (Section "OpenGL and OpenGL ES Integration") for more details.
Related
I am looking for some information about rendering child windows in specific about how OpenGL interop with GDI. The problem that I have is that I have basically is that I have two windows, first, the main windows are created in qt, and inside of qt, a child window is hosted that leverages an OpenGL renderer.
Now what I wanted to do is to host an overlay on top of my OpenGL window, so I use that to overlay the OpenGL window. The problem that I am having is that when I render with OpenGL, the OpenGL generated graphics seem to obscure the graphics area including and effectively undo the graphics composited by qt.
In the image below the blue area is the qt overlay, in that picture I'm using GDI (BeginPaint/EndPaint) so and the windows seem to interact fine. That is, window order seems correct, the client region is correct. The moment I start to render with Opengl the blue area gets replaced with whatever OpenGL renders.
What I did I basically created to create the overlay I created a second frameless, topmost QMainWindow, and once the platform HWND was initialized I reparent it. Basically I change the new windows parent to be the same parent of my OpenGL window.
What I believed this would do is that the every window, gets drawn separately and the desktop composition manager would make the final composition and basically avoiding the infamous airspace problem as documented by Microsoft in their WPF framework.
What I would like to know is what could cause these issues? At this point, I lack understanding why once i render with OpenGL the pixels by qt overlay are obscured, even though windows hierarchy should say make them composited. What could I do to accomplish what I want?
Mixing OpenGL and GDI drawing on a shared drawable (that also includes sibling / childwindows without the CS_OWNDC windowclass style flag) never was supported. That's not something about Qt, but simply how OpenGL and GDI interact.
But the more important issue is: Why the hell aren't you using the OpenGL support built right into Qt in the first place? Ever since Qt-5 – if available – uses OpenGL to draw everything (all the UI elements). Qt-5 makes it trivial to mix Qt stuff and OpenGL drawing.
I'm creating an application, which interacts with OpenGL via QOpenGL* classes. The graphics is shown through a QOpenGLWidget, which is placed in a UI-form.
Now, there is a library for CAD purposes (Open CASCADE), an OpenGL interface of which requires a handle to the render window. The question is: can I somehow say the library to render everything to the mentioned widget?
In other words, is there a way to interpret the widget as a native, probably, platform-specific (HWND here) window, so that the library renders its own stuff exactly there?
Thanks
QOpenGLWidget is not the same thing as QGLWidget.
The classical approach for embedding OCCT 3D viewer, which you can find in Qt IESample coming with OCCT, creates QWidget with unique window handle flag, takes this window handle and ask OCCT to take care about OpenGL context creation for this window. This is most straightforward, robust and portable way with one limitation - Qt will not be able drawing semitransparent widgets on top of this QWidget. This is not a limitation of OCCT, but rather limitation of Qt Widgets design.
QOpenGLWidget was intended to solve this limitation by allowing to mix custom OpenGL rendering and normal widgets. The integration of external OpenGL graphics engine, however, became more complicated and fragile. It is not very helpful stealing winId() from QOpenGLWidget, as rendering content is expected to be drawn not into window itself, but rather into OpenGL framebufer object (FBO), created by QOpenGLWidget - see QOpenGLWidget::defaultFramebufferObject() property.
External renderer is expected to render into this FBO for proper composition of Qt widgets. Luckily, OCCT is flexible enough to allow such integration. Unluckily, such integration requires some knowledge of OpenGL, as well as its usage by Qt and OCCT.
For that, you need to ask OCCT wrapping OpenGL context already created by Qt (for that V3d_View::SetWindow() provides an optional argument of type Aspect_RenderingContext, which corresponds to HGLRC on Windows and can be fetched using wglGetCurrentContext() within rendering thread) as well as FBO created by QOpenGLWidget (for that, OCCT provides OpenGl_FrameBuffer::InitWrapper() and OpenGl_Context::SetDefaultFrameBuffer() methods, as well as OpenGl_Caps::buffersNoSwap flag to leave window buffer swapping management to Qt).
OCCT doesn't come yet with a sample using QOpenGLWidget, but you can find also qt/AndroidQt sample implementing similar thing for embedding OCCT 3D Viewer into QtQuick application.
After some investigation, I found that method QOpenGLWidget::winId() returns the correct handle. It's been found out only now, because the rendered scene disappeared immediately, leaving a black picture instead. However, when the viewport is resized, the scene returns back (and disappears again, though). Looks like Open CASCADE has problems with Qt 5 OpenGL implementation, since QGLWidget didn't have such problems, as far as I know.
How to put a label or button into qt3d window? Is it possible? Havent seen any example... I was trying to simply put qt3d in windowcontainer, assign layout to it and layout->addWiget() but it just doesnt work.
I know this is a farily old question but I wanted to give a more detailed answer if anyone else stumbles across this.
I implemented a Qt3D widget which you can find here. Unfortunately it relies on a method to obtain the texture id from QAbstractTexture which is only available from Qt >= 5.13 so that's the minimum version you have to use.
createWindowContainer draws the respective window above everything else. So you'll never be able to draw any buttons inside the container.
You can of course have buttons and everything else around your containered 3D window. But that's specifically not what you wanted.
You can use Dear ImGui - and it's Qt3D integration. ImGui is used to draw GUI elements using vertices in 3D environments.
Of course you can always use QML - there you should be able to place buttons inside the 3D view.
you have both label and (radio)buttons on the first example for C++ into the QT3d documentation, refer to Qt 3D: Basic Shapes C++ Example
QExtrudedTextGeometry seems to be the class for 3D text
I am new to Qt and I want to use Qt to make interactive geometry programs using CGAL. I would like the user to input, say points, segments, using the mouse and then push a button to get a CGAL algorithm working on the input.
My environment is CGAL 4.5, Qt 5.6 and QtCreator 3.6.1 on an Ubuntu 14.04 machine.
CGAL has builtin support for its objects to be
rendered using the QtGraphicsViewFramework (http://doc.cgal.org/latest/GraphicsView/index.html )
I don't know how to render CGAL objects -- points, lines, rays, polygons -- onto a Qt window. The page I linked to above assumes a knowledge of Qt to get an application working, and so is not helpful to a Qt beginner.
Thus far, I have created a Qt widgets application project using QtCreator. From what I know, I need to modify the mainwindow.ui file graphically inside QtCreator by dragging and dropping different kinds of widgets onto it and then map signals calling CGAL functions onto slots of whatever the drawing canvas widget will be. (Is this correct? I am shaky on the signals and slots mechanism)
MY QUESTION IS....which widget do I place onto the window as a drawing canvas? Two relevant widgets seem to be GraphicsView and OpenGL widgets
under the DisplayWidgets menu. But how do I use them?
I have no CGAL experience, but I can give you some Qt-related hints:
Use the QGraphicsView + QGraphicsScene. If you want, you can enable OpenGL support like this:
QGraphicsView view = new QGraphicsView(parentWindow);
view->setViewport(new QOpenGLWidget(view));
To draw CGAL objects you have to use either provided graphics item classes (CGAL::Qt::TriangulationGraphicsItem, CGAL::Qt::VoronoiGraphicsItem, ...) or derive your own from the CGAL::Qt::GraphicsItem. To add an item to the scene, use the QGraphicsScene::addItem() method.
To navigate (pan + zoom) the view, CGAL provides the CGAL::Qt::GraphicsViewNavigation class. This is how to use it:
CGAL::Qt::GraphicsViewNavigation* navFilter = new CGAL::Qt::GraphicsViewNavigation(view);
view->viewport()->installEventFilter(navFilter);
Recently I want to write a gui application, and its appearance is shown below:
I used MFC before to write normal gui applications, but I have never used qt to write gui applications. But this time I want to use qt, so i'm wondering is there any way to implement such interface, integrating with opengl and opencv subwindows within one application.
Please give me some directions on:
1. Which kind of widget can I draw opengl and opencv subwindows in my application?
2. Is there any way to do event handling in those subwindows respectively?
3. How does qt support for opengl and opencv integration?
There should be no problem.
In fact, I've used openCV and OpenGL in different projects, but I don't see any problem.
You have to convert opencv cv::Mat to QImage (see various posts on the problem on StackOverflow) and then draw on a QLabel or a subclass of it.
For openGL there are special classes: http://qt-project.org/doc/qt-5/qtgui-index.html#opengl-and-opengl-es-integration
You should use event handling as usual in Qt (signal-slot, you know).