Qt ui on top of c/c++ code - qt

I saw this thread: QML UI on top of OpenGL rendering in Qt5.3 but it's not what I am looking for.
My question is if I have a program already written in c/c++ and would like to add ui to it in the most cross platform way. Qt seems to be the way to go, is it possible to just link the Qt library 'hopefully not too large' into my application and create menus, buttons etc that work in a cross platform way?
I don't want to build my app using Qt, I just want to use the layout widgets, menus etc.

I don't want to build my app using Qt, I just want to use the layout widgets, menus etc.
What?
In any case you should make an UI (using Qt Widgets or Qt Qml) and UI logic, and connect it to your app API. Just add UI layouts (using Qt Designer) and connect UI actions for button/menu/etc. to your app.
Qt - is the most cross-platform way to go, today.

Related

Is resolution independent UI possible directly using QtDesigner?

I want to create a UI which remains the same in all possible resolutions. I started with the Qt Designer wherein I set the geometry of my design window and when I change the resolution , the UI is not the same.
Things I tried:
1.I got the screen resolution using QT API and created a window programmatically to that resolution.But if this is the right approach,then I have to add other components programmatically. But my UI is quite big and it is time consuming creating all the UI components programmatically.
I looked at the following links:
Hand Coded GUI Versus Qt Designer GUI
Qt Creator - How to write the UI?
Is it possible to rescale a Qt GUI without rewriting the code?
but still I am a bit unclear of how to proceed.
Is there any way to achieve resolution independent UI using Qt Designer itself?If so, what is the approach?Else what is the work around?

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.

which Qt project type we should use?

New to Qt. In the official Qt tutorial, it says:
To set up a project, you first have to decide what kind of an application you want to develop: do you want a user interface based on Qt Quick or HTML5 or Qt widgets.
We plan to use Qt to do medical image display, and also use Qt to build a GUI application to control a medical device. They will be two different projects.
Which Qt project type we should use for them?
Docs say:
QWidgets are a better choice if your UI is comprised of a small number of complex and static elements, and QML is a better choice if your UI is comprised of a large number of simple and dynamic elements.
I say:
If you're going for desktop applications I'd suggest Qt Widgets, you don't have to ship the final app with libs for QML and the whole source will be written in C++ (faster, simplier so easier to debug).
QML would be a nice alternative if you want to create phone/tablet (touch experience in general).
I would argue that between Qt Quick and Qt Widgets there is no objectively right answer. In theory, one should be able to replicate any UI using either method - because at the end of the day, they are both using QtGui behind the scenes. So functionality is probably not an issue.
One thing to note is that Qt Quick (i.e., QML) is designed explicitly to make UI programming require much less code, and much less C++ knowledge. I would say it achieves this goal very well.
However, at the end of the day, I think it mostly comes down to what language your developers are already familiar with. If you have a team of C++ pro's, then I would go with Qt Widgets - if only because it's going to be very easy for them to pick up, and it's something they're already familiar with. (I'm guessing this is the case because you're already writing C++ code for your project).
If, on the other hand, your developers are already very good at QML (or, more generally, JavaScript - which QML is heavily influenced by), then I would go with Qt Quick for the same reasons.
I know of two types of Qt UI: Qt Quick and widgets.
Widgets behave like most other UI toolkits out there, you have a GUI editor and a tree of UI objects. They are pretty mature and look like most standard UIs.
Qt Quick is the newer Qt UI toolkit. It uses a domain specific declarative language (QML) to specify the user interface and JavaScript for interactions. There are also plans to offer Qt widgets inside the Qt Quick framework, but I'm not sure how far that project has gotten. Qt Quick is meant to deliver more dynamic / custom user interfaces.
As far as I know Qt will continue to support both approaches in the foreseeable future so which one you pick depends on your use-case.

How to programmatically add a UI to a widget based on a Qtvtkwidget?

I am trying to write a program based of of this example i.e. a widget based on QVTKWidget, so that I can use the PCL Visualizer inside the widget, with no UI and the first step for me would be to add a simple UI a menubar with some simple options: close,save etc.
Unfortunately my experience with QT interfaces is with the Designer, I have though seen what ui files look like but I have seen no tutorials on how to add them to widgets, tutorials for adding them to main windows I've seen a few.
Do you know of a simple method to add a .ui file to a QVTKWidget or a widget in general?
The easiest way to do this is to create an application, or a widget in designer, then add a plain QWidget into the content, this QWidget you promote to type QVTKWidget, through the designer interface as described in the documentation. Then you can add all the other ui elements to the application and interact with the QVTKWidget

Embedding Qt GUI into existing OpenGL program

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.

Resources