Modern looking UI with QT - qt

I have an wizard application written in C++/MFC that I want to improve the UI. Different buttons, change the dialog background color, etc. Could I use QT to improve the appearance or should I change to WPF and C#?

Qt 5 gives you essentially five (5!) UI toolkits:
The Gui module that is similar to what you got with a very good 2D graphics library in the late 1980s/early 1990s. You have access to the buffer of the window and to key/mouse events. Everything else is up to you. This would be the fastest way to port an existing application from "back then". The graphical primitives are neat, with fonts, painter paths, gradients, etc. but there's no notion of a widget, only of a top-level window. You draw everything where you want it to be within that window.
The provided concepts are at a higher level of abstraction than typical platform toolkits like winapi or xlib. In terms of graphical primitives it is more akin in spirit to Cairo or PDF.
It is possible to parallelize the painting of a QRasterWindow in the same way as it is done for QWidget.
The Widgets module gives you Qt4-style widgets and layouts, with customize-able styles. This is the model perhaps most like MFC, although it has much more functionality. The widgets are so-called alien widgets - it means they don't have native window handles. This keeps things fast. You have a multitude of pre-written widgets to do user input/output of all kinds. It is possible to parallelize the painting of a widget..
The Declarative module, a.k.a. Qt Quick 1, uses the QGraphicsView widget from the widgets module to display a graphical scene. This scene is described using QML. The controls are fairly rudimentary and there's no platform-specific styling. It will look all the same no matter where you run it. There is good support for animations/fluidity in the interface.
The Quick module, a.k.a. Qt Quick 2, uses a new OpenGL ES-based scene graph and can run on top of either a widget from the widgets module, or a raw window from the gui module. The scene is described using QML. There is a desktop components set that gives you platform-styled controls like combo boxes, text inputs, tables, etc. The new scene graph can really leverage the hardware and will outperform both widgets and Qt Quick 1 when you have heavy animated UIs. This is the way to go for the future. Qt 5.2 brings in an entirely new Javascript engine and a new scene graph renderer, with even better performance. Qt 5.11 brings in a new Javascript engine again, twice as fast.
The 3D module, exposed both via C++ and QML APIs, is a high-level 3D object and scene rendering system, tailored for interactive applications. It makes it easy to implement user interaction with 3D objects. The C++ and QML APIs are peers and can be used per your preference - this is in contrast to Qt Quick, where the only the QML API offers the full functionality.
Both Qt Quick 1 and Qt Quick 2 can wrap existing widgets at very modest performance cost, but you do lose out on some of the niceties of "native" QML objects.
Do note that there's a separation between the need for an OpenGL implementation and there being one provided on your system. On post-Windows-XP systems (Vista, 7, 8, etc.) you should normally use Qt 5 with its own ANGLE implementation of OpenGL ES 2 that runs on top of DirectX. Only on Windows XP you're forced to use the system OpenGL drivers.
Qt is a generally very nice framework to work with even for non-gui applications. It has good cross-platform abstractions of networking and file I/O, time/date, and provides a bunch of other general-purpose goodies. It is relatively easy to use it alongside ncurses, for example.
The fastest way to port existing MFC code would be to stay with C++ and use Qt with the qtwinmigrate solution. The latter is a BSD-licensed shim layer that can get you up and running very quickly.

Related

Is it a bad practice: embed QML in a QT dockable widgets application?

the QT widget is very time consuming in terms of UI development, my CSS sheets has 3000 lines of code already and it is very time consuming to do UI changes. My application is very demanding in terms of performance, I was thinking of embedding the widgets into QML to have easier and faster control of the UI but I'm really worried about performance, will worth the try or it is just bad practice?
My application is very demanding in terms of performance, I was
thinking of embedding the widgets into QML to have easier and faster
control of the UI but I'm really worried about performance, will worth
the try or it is just bad practice?
Since Qt 5.1 we can easily embed QML view to Qt Widget container. There is a blog I stumbled upon some time ago: Combining Qt Widgets and QML with QWidget::createWindowContainer().
As for performance, unsure what kind of performance is in demand for your application? Overall QML renders to screen via OpenGL or very fast. On the other hand with QML you often need to deal with JavaScript which of course is not comparable to C++. There is Qt Quick Compiler introduced to commercial Qt, though.
As for QWidget-based UI vs. QML: the discussion can be considered an expression of opinion etc. Some consideration points then:
Developing and maintaining one kind of UI, either widget or QML based is easier.
Hybrid UI is possible but it makes sense to understand what you can gain from it.
Most desktop apps are fully satisfied with widgets only.
When the app supposed to be ported to mobile platforms as well then QML makes more sense.
When the app supposed to rely on 'touch' then QML is also more beneficial than widgets.
the QT widget is very time consuming in terms of UI development, my
CSS sheets has 3000 lines of code already and it is very time
consuming to do UI changes.
Hmm... very heavily styled widget-based app? I can only be sure that these two concepts: widgets and QML are very different but both widget stylesheets and QML are declarative language though different. I am also sure that any serious app needs more of C++ and with QML we need to spend time bridging C++ code with QML.
And the distribution of QML apps can also be a bit more complex than purely widget-based: for instance you need to customized Qt build to support OpenGL emulated for certain VMs and platforms: that is one interesting topic. Also with Qt Quick widgets you use should put them either to resource distributed with the app or you need Qt Quick Compiler. And if you use it, be sure that all QML code was compiled by it and no part of the app still uses 'scripted' QML which is missing from resources. I made use of Qt 5.5 Quick Compiler in our app and found not only quite a few bugs with it but also still needs to drag certain Qt Quick files from framework together with the app install package. That is not as bad with standard dynamic link and windeployqt tool. But a serious app often needs to be statically linked with all its dependencies and then we cannot use windeployqt tool.
Overall Qt is departing from widgets to QML but what can we gain and how much we need QML in our real applications is a long discussion.

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.

Implement with QML or C++?

I've just started learning Qt recently, finding QML quite interesting for implementing UI component. Before the project really kick off, I've got some questions:
For a fresh start project, should I just use QML? Does QML be designed for replacing QWidget?)
If I go with QML, is there anything else must be implemented with C++? Or better implemented with C++ for better performance? (I know some customized UI components can be integrated through plugin) What's the relationship between QML and C++ widget?
As for performance or rendering issue, does QML better than native C++ widget?
When you start a question with 'Should I use', it is quite a good hint that SO might not be the right place to ask it. Even more when there are only answers, which start with 'It depends on...'.
QML is not designed to replace QWidget. It is a different technique. Which one to use, depends on your requirements.
Whether or not you must implement additional stuff in C++ depends on your project. Some things are easier in C++, others in QML. And some stuff is not possible in QML at all.
There is no relationship between QML and C++ widgets.
And the performance of QML is in most cases more than sufficient. In almost every case QML is used to create user interfaces. I doubt that there are many cases where clicking a button or opening a dropbox folder is performance critical.
I had a chance to put this question to a few Qt experts at the World Summit today and the general take was that because QML component rendering can be done through hardware acceleration that it is preferred for apps requiring high performance graphics, eg automotive dashboards. OTOH widgets seem to be used for desktop applications. Another consideration is that while widgets can be styled using Qss (Qt's version of Css), QML components cannot.
In QML based applications computationally intensive functions are generally written in C++.
HTH,
Eric G

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.

Designing modern Desktop GUI

I want to develop a desktop program, and one of the most important criteria is having a wonderful user interface - both in terms of usability and style. When I say style, I mean the cool designs (and effects) that one normally associates with Android/Apple applications. I wish to design a user interface, similar (or inspired from) to the one designed for Light Table by Chris Granger. Here's the link to Light Table: http://www.kickstarter.com/projects/ibdknox/light-table
Even Autodesk Maya has been designed using Qt.
Also, I wish to design the interface by drag-n-drop methods, so I finish the interface part quickly and move on to other important parts of the program.
I've worked with Java Swing and AWT. But they provide native interfaces, which are good and easy to use, but doesn't fit the style/cool factor. So I tried Qt. Qt is a major improvement over Swing, I felt. But being new to it, I haven't been able to judge it's full capability. Interfaces of VLC and Maya have been designed with Qt, so I know Qt is the way to go.
Now, Qt provides two major tools for UI design - Qt Designer and Qt Quick.
Their docs and site say that Qt Designer should be used for Desktop applications and that it would give you a native style interface. But I don't want a native style interface. Qt Quick on the other hand, promises to give me exactly what I want (stylish looks etc), but their doc says Qt Quick is to be used for Mobile Application.
Is it possible to use Qt Quick for desktop UI design?
Or, is it possible to extract out of Qt Designer, the kind of design I wish to implement?
I also liked the Autodesk Maya interface design and would like to give my program that kind of touch.
Besides, are there other or better cross-platform tools for UI design. Another reason for me choosing Qt is it is cross-platform. I want my program to run on Linux/Windows/Mac all the same.

Resources