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);
Related
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 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.
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).
When I browsed the source code of Qt I didn't find how it actually draws a GUI component, but I know it uses OpenGL.
I want to know how does a GUI library like Qt draw its GUI components (ex : QPushButton ,QWidget)?
Can any one help me with a basic idea ?
In Qt-project site :
Qt is painting QtWidgets using QPainter, which uses (usually) the raster engine to draw the content. It is not using native OS calls, apart from few exceptions (file dialog, for example, which can be drawn either natively or using QtWidgets).
QtQuick is painted using scenegraph, so OpenGL. Also, no native OS calls here.
I think you either misunderstood (there are several meanings of the word “native” in computing) the stackoverflow post, or your information source is wrong.
OK, then to be clear: by “native” I’ve meant using native OS controlls, like wxWidgets library does: asking the OS to draw native scroll bar, or combo box, etc. Qt does not do this. It paints all the widgets itself, and only tries to mimick the looks of the OS it is running on.
But obviously, some kind of native OS calling is happening deep inside, in order to actually draw some pixels on the screen, and open native window container. But that is usually not important at all to high level UI developers.
You have a clear choice whether the widget should be drawn by the CPU or the GPU: widgets can use different painting methods (native, raster, OpenGL, for more see here! [qt-project.org]), and the user has choice which one should be utilised. Most people do not use that, though, because the default settings work well.
Thanks.
I'm trying to develop a cross platform (or at least desktop + embedded hardware) application. I would like to use Qt Quick to create a touch friendly GUI. I have been implemented a classical application with a QGLWidget displaying data. It is important that only a part of the window is in OpenGL. Because of this there are problems with EGLFS and LinuxFB. Only X11 (or maybe Wayland) can display the application properly (others generates a couple of errors about missing setParent function and the whole screen is black). Now I'm trying to achieve the same thing in QML. I want to use this OpenGL renderer as part of my QML application and some Qt Quick widgets around it. I found a couple of people asking about the same thing and the answer is always to subclass QDeclarativeItem and call the painter's beginNativePainting() (the others says to export it through QDeclarativeItem, but I cannot figure out how to do this). The problem is that on desktop, Qt 5.11 the native painter is not OpenGL. And in QT5 there is no way to force OpenGL graphics system. So when I try to get the OpenGL context (QGLContext::currentContext()) I always get NULL. Another problem: If I export my widget with qmlRegisterType("Test", 1, 0, "Test"); it becomes only visible when I use QDeclarativeView, but then it doesn't sees Qt Quick. If I use QQuickView it says module "Test" is not installed. How can I implement this properly?
QDeclarativeItem is from Qt Quick 1 and Qt4. With Qt 5 and Qt Quick 2 you should use QQuickItem.
There is at least 1 example of this provided with qt docs, which you can find in Qt Creator in the Welcome tab in the Examples section.