Qt and QML for UI and layouts. QtQuick - qt

I know QML is fine for making interfaces in Qt but, how about the layouts of these interfaces?
I want to make an application looking like similar to, for example, spotify. But I want layouts to be "movable" and completely customizable by the user. Is it difficult to make that through QML? Should I better use the usual Qt layout stuff (gridlayout, graphicwidgets, graphic items...) ?

Layout of QML elements works by using anchors attached to other QML elements. You can change anchors at runtime by using Javascript. Building a flexible GUI with QML is possible but challenging because the documentation is sparse in some areas, and debugging is difficult.

Qt Quick Layouts were added in Qt 5.1. They work similarly to layouts in standard widget-based Qt and are usable in Qt Creator.

Related

Drawing with EGL in Qt

I'm trying to get Qt and EGL to work together. I'm working on a program that uses EGL to draw, and I have to use Qt to create a GUI overlay.
The current solution was to turn a QWidget into a native window, and pass it's window handle to EGL. This works, but it's difficult to work with. Qt isn't aware that the widget is being drawn in by something else. So when another widget is overlaid, even if it's transparent, the image drawn by EGL is erased. The only way to get them to work is if I jigsaw the buttons and other GUI elements in a way that they don't overlap the parts of the native window I want to show. However this means that I can't use layouts or QML or any of the tools that would make creating different GUIs easy.
So my question is, how can I draw with EGL into Qt in a more usable way.
I'm working with Qt 5.4.2 by the way. If absolutely necessary, I might be able to upgrade to 5.5, but newer versions won't work.
I was looking into QOpenGLContext, and ways to make it use the context created by EGL, but I can't seem to find any good examples on how to actually go about doing this.

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.

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

Creating a home screen for my embedded board using Qt/Qt Quick

I am not an expert but I have been using Qt/QtEmbedded for sometime now, for SBC 6845. I have created a few applications and have successfully run them on my device.
Now I want all of those applications to appear on a home screen. I understand that using QML/Qt Quick this might be achieved, but I don't have any idea on how to proceed with it. I have gone through some links and tutorials but most of them show how to create buttons and all that with Qt Quick, but not much than that. I am yet to find some tutorial/docs which can point me how to proceed with all applications on my home-screen. I need some directions, any links, advice on docs/books is welcome.
[While cross-compiling the QtEmbedded 4.6.2 libraries for my SBC I encountered problems with enabling opengl support. And, I am unaware of the other methods for using QtQuick2 without opengl.
The applications (5-6 of them) are QWidgets and linking icons require to stay in the home screen. I want to keep them as simple as possible without any effects for the icons.
Plainly speaking, I am trying to create a bunch of icons displayed on the home screen linked to those applications. The applications if launched in windows style application, (or like a popup QDialog) will also serve my purpose.]
Thanks.
"I have gone through some links and tutorials but most of them show
how to create buttons and all that with Qt Quick, but not much than
that"
For this part of the question, I'd advise you to download QtCreator
and start playing with the demos (using more than just some buttons:
you have demos for ListViews, GridViews, Delegates, Animations,
Particles, QtQuick Layouts (Qt5.1 only), QtQuick Controls (Qt5.1
only).
There's also the rather complete :
http://qt.gitorious.org/qt-labs/qt5-everywhere-demo
I'm completely unfamiliar with all the embedded/cross-compiling
aspects of your question.
About OpenGL/QtQuick2 : http://qt-project.org/forums/viewthread/30483
http://qt-project.org/forums/viewthread/17201
Also note that you can embed QtQuick2 scenes into a QWidget, but not
the other way around (no QtWidget inside the scenegraph).
So maybe the easiest/fastest way to go for you would be to stick with Qt4 or Qt5 declarative/QtQuick1 module (might be deprecated/removed starting with Qt 5.2). In this setup, there is no scenegraph/mandatory need for OpenGL. And you can embed QWidgets into your qml scene (no scenegraph: it uses the QGraphicsView backend) via QGraphicsProxyWidget.
You'd then have some GridView (you also could use some Grid with a Repeater) filled with models and delegates (= a delegate acts as a template item to be filled with the model).
Your delegates would have states/maybe Loader(s) (for on-demand loading) : icon state and when clicked, some maximized state containing a loader, loading your widget through QGraphicsProxyWidget.
You already have half of this presented in this example (a grid + 2 states : small icons grid and maximized view, you only need to implement the delegate/loading/model/QGraphicsProxyWidget things):
http://developer.nokia.com/Community/Wiki/Implementing_parent_change_animation_with_QML

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