Embedding Qt GUI into existing OpenGL program - qt

I'm currently trying to get Qt working with my existing program.
I'm using SFML for creating my OpenGL rendering context and creating the window. The things I tried out so far however always create a separate window by Qt instead of just rendering into the existing context.
Is there any way I can force Qt to render to an already existing OpenGL context?

I've not looked into the specifics, but this has been done for openage.
I think looking at the documentation for QQuickRenderControl might be a good place to start.

Qt wants full control over the windows and the event loop, so this will not work (unless you put a lot of effort into it). Your best bet is using a QGLWidget and emulate the event management of SFML with that, so that your application effectively runs on Qt. It is very well possible to render Qt widgets into a OpenGL window (Qt has a OpenGL widget backend) but this must be still managed by Qt itself.

Related

How to use OpenGL in QT Creator

I am working on OpenGL to create a GUI .I want to create some tabs which will help me to display different things in different windows. How is this possible using OpenGL? I read in some articles that we can use QT for that. Since I have already developed some of the GUI part in OpenGL using GLUT library ,is it possible to use the same code in QT? If so brief me how to make settings for OpenGL libraries in QT creator.
In my GUI I am trying to create a Car which is following a track.
I think you might be mixing some things up: OpenGL is a API with which you can instruct drivers to draw visual primitives, like lines, boxes, 3D triangles, pictures from buffer onto a render plane.
GLUT is a library that gives you a minimal environment around that, ie. it handles creating a window etc.
Neither of them are high-level UI description tools. Qt is really most likely what you want, as it will not only give you things like tab widgets etc, but also a feature-rich framework to do things like defining what should happen when you click a button, close a window etc.
There's a lot of examples of OpenGL usage within Qt widgets. In fact, a lot of visualization frontends use Qt and OpenGL. Qt has extensive documentation on how to generate OpenGL contextes and draw inside Qt applications.

How to install a eventFilter to a WinOS window in Qt?

I have got the handle of a WinOS window,eg. Internet Explorer window, in Qt.I did it in this way:m_hwndUnderCursor= WindowFromPoint(curPoint);
How can I install a eventFilter to m_hwndUnderCursor by QWidget::find(m_hwndUnderCursor)->installEventFilter(this); successfully,so that I can watch m_hwndUnderCursor in Qt without HOOK technology.
I know because m_hwndUnderCursor a pointer to a WinOS window so QWidget::find(m_hwndUnderCursor) always return NULL.Is there a way to make it?
A quick answer is: you cannot do this.
A more detailed answer:
The QObject::installEventFilter() works basing on Qt's events engine (the event loop, events propagation, etc). This is Qt's internal stuff and this is not available to other windows, outside the Qt application. It will only work with windows that are part of the same application that you're calling installEventFilter() from.
For similar reason the QWidget::find() will never give you an existing QWidget in result if you try to find non-Qt window. It works only with windows created within your Qt application. Also see this: Can QWidget::find find widgets from a different process?
You will have to deal with it using native Windows API.

Qt 5.x Custom Widget Creation and Use

I'm returning to Qt programming after an absence of a couple of years, and I'm starting with Qt 5.1. In the past, I've used the designer, and a good deal of hand-crafted code to put Qt projects together. Now, we'd like to make heavy use of the Creator.
But I'm not seeing how to accomplish some seemingly basic tasks. For example, I'd like to design a custom widget, then pull it into my main application, but although the Creator allows me to make multiple files within a project, they seem to have no knowledge of one another as far as the Creator itself is concerned. Once my widget is built, there's no way to pull it into the main application, and also no way to test it independently, at least that I'm able to find.
It seems as though documentation for Qt has taken a major blow somewhere along the line. It is cursory and thin, compared to the extremely detailed docs that used to be available in the past.
If someone can point me to a decent collection of documentation and tutorials, I would be grateful.
Unit Testing
Use the Qt Test module: https://doc.qt.io/qt-5/qttest-index.html
Using Custom Widgets
I'm not 100% sure what you meant by "pull [the widget] into the main application".
If you want to combine your custom widgets in Qt Designer, add a placeholder (blank) QWidget in the parent and Promote it to your custom widget:
https://doc.qt.io/qt-5/designer-using-custom-widgets.html#promoting-widgets
If you want to combine your custom widgets in C++, instantiate your custom child widget and add it into the parent widget's layout using QLayout::addWidget():
https://doc.qt.io/qt-5/qlayout.html#addWidget
If you want to make your application display a custom widget, simply #include the widget's header, instantiate the widget, and call QWidget::show():
https://doc.qt.io/qt-5/qwidget.html#show
If you want to develop your custom widget in a separate standalone project, include it in your main project as a Subproject:
https://doc.qt.io/qtcreator/creator-project-creating.html#adding-subprojects-to-projects
How do I make a subproject with Qt?
Other Notes
Qt Designer has been integrated into Qt Creator for many years. Qt Designer and its documentation have changed very little between Qt 4.8 and Qt 5.
The extremely detailed docs for Qt 5 are at https://doc.qt.io/qt-5/. There are links to useful doc collections in the nav bar on the right.
I recommend exploring QML/Qt Quick. It's much easier to create QML-based GUIs compared to widget-based GUIs. It's still a young technology though, so it might not suit your needs yet: http://doc.qt.io/qt-5/qmlapplications.html

Qt 5 General Questions about QT / QML and Widget customizations

I am an iOS / Cocoa developer looking to port one of my apps to PC platform. I don't care to code multiplatform and maintain one app. I will continue using cocoa and cocoa touch for iOS Mac Development.
I have chosen to use QT 5 for PC, I am not sure if its wise choice but its easy and I can understand c++. If its not please point me to the correct direction.
My App is not hugely complicated, but needs some special customization e.g. ListView that looks like an iOS Table View, uses custom rounded windows with twitter bootstrap style search box and I want to monitor some global OS events like keystrokes, and what other applications the user is currently working with. I also use SQLite and AES encryption.
My questions is regarding UI customization.
Should I start studying and use QML for that? I am not sure what exactly it is, seems extremely simple CSS like, but I have the feeling is more designed for embedded devices and have limitations...
Do I have access to the entire power of QT if I use QML ?
What other options I have to customise widgets instead using QML (e.g. in objective C we use subclassing and drawing whatever we want or handling events...)
I am inexperienced in windows platform. Should I use VisualStudio C++ instead of QT5? With the changes in ownership I feel somehow insecure.
Yes you should. QML is declarative language which allows javascript to be executed within it. And you can do almost anything UI related with QML. If you don't have some particular UI element you can draw it in plain C++(Qt) and use it in the QML. So QML is the best choice for Qt development at the moment. It is not like CSS though, it is much more powerful.
Yes you have all the power Qt has and additional power which declarative language may offer - simplification of UI development process as well as modern decomposition of UI&logic.
You have this option in plain C++ Qt, you may subclass widget, redraw them, change behavior etc. This approach is inferior to the QML one.
This point doesn't make sense. Some people count Visual C++ like separate language which is wrong. You may count Visual C++ as C++ + some minor extensions MS compiler has. But it is as ridiculous to refer as GCC C++. So basically you can use Visual Studio with Qt almost without a pain if you use Qt integration add-in which is freely available. Or you can choose Qt creator, which some people count as superior to MSVS. It is up to you what to choose, but I believe for the novice it is much simpler to use Qt creator with Qt. But note you will need to have some compiler because Qt creator is just an IDE it should use some 3rd party compiler(either MS or GNU one)
You can use QML Desktop Components to build easily your application:
https://web.archive.org/web/20121203050945/http://blog.qt.digia.com/blog/2012/06/06/desktop-components-for-qt-5/
http://qt-project.org/wiki/Qt_Quick_Components
Anyway I recommend you use Qt Widgets and Qt Style Sheets to costume your widgets:
http://qt-project.org/doc/qt-4.8/stylesheet-reference.html

Qt+OpenGl+SimpleGl

I have enabled qt+OpenGl+SimpleGl on one of the ARM platform and was able to run opengl example programs.
I also has a qt+Webkit, which is working with a graphic plugin.
I wanted to use simpleGl context for every thing, instead of using the normal graphic screen. So, when I try to run Qt+Webkit with simpleGl, I just get a blank screen.
Does QT support this? If so how can we make it?
Yes, this is correct. OpenGL draws directly to the framebuffer. The simplegl driver doesn't handle what is drawn using the raster paint engine of the QWS, so you may see only black.
Using simplegl for "everything" means you want everything to be drawn using OpenGL in your EGL full-screen window? This is possible under some assumptions. You have to write all your applications to be rendered using the Qt OpenGL paint engine (using the opengl graphics system is not supported under Qt/E). This is possible also for QtWebKit, I'm doing it now. Note that this does not mean that everything is rendered using hardware acceleration. You'll have to write your applications "the right way" to get all actually hardware accelerated. Consider that you'll have to handle the mouse pointer some other way in this case.
The other way is to just modify the simplegl driver to allow for the use of Qt applications using the raster paint engine. This is possible as well with some limitations. Qt can use blit to place its own windows over OpenGL. Look for the framebuffer driver inside the Qt source tree to know how to do this. You can then have common Qt applications and OpenGL Qt applications some way. I'm doing this as well. Not everything can be done anyway.
EDIT: I'm sure you already did, but in case, give this http://doc.qt.io/qt-4.8/qt-embeddedlinux-opengl.html much attention.
Unfortunately I don't know anything about SimpleGL, but I do know that there is a way to render a standard Qt widget in a QGLWidget. Maybe have a look at this Qt Quarterly which I think is somewhat related to your question:
http://doc.qt.nokia.com/qq/qq26-openglcanvas.html

Resources