2

is there a way of creating a classic GUI with cpp like for the case of JavaFX? I want to create elements like floating buttons, tables, graphs, etc. I know of tools like qt but I'm not ok with it. I tried win32 API but it's only for Windows.

Wafula Samuel
  • 530
  • 1
  • 8
  • 25
  • 1
    I don't agree JavaFX being a classic GUI framework. JavaFX or swing or WPF for C# are advanced frameworks for GUI's. java.awt resembles classic GUI and there are a lot of C++ GUI libraries on this area. The closest thing to JavaFX is QT afaik, [with their animation scripts and all](https://www.youtube.com/watch?v=VAhLnJc5iEY). – zahir Nov 20 '16 at 07:12

1 Answers1

6

GUI libraries are generally called "widget toolkits", and there are a variety of cross-platform GUI widget toolkits available, however they are rarely a good idea for a great UX because different operating-system environments have different UI paradigms (e.g. how macOS and Ubuntu has a single always-on menu-bar at the top, whereas Windows and other Linux desktops do not).

So you have two fundamental choices to make:

  1. Use a single cross-platform GUI toolkit - which means creating a single GUI project, but restricting you to that toolkit's selection of controls and functionality, and generally subjecting your users to a (relatively) poorer user-experience, either because your toolkit does not use native widgets (e.g. Java, WPF, Qt) or because you cannot use a platform's native paradigms.
  2. Write a new native GUI for each platform. This means more work, but a better user-experience.

For cross-platform GUI toolkits, the main options are:

  • Qt
  • GTK+
  • WxWidgets

For a comparison between the three, see this QA: Which, if any, achieves Windows native look: GTK+, wxWidgets, Qt, FLTK?

(TL;DR: WxWidgets uses native controls but is difficult to develop with; Qt offers the best developer experience but has many other bullet-points which you need to be aware of)

For a native UI for each platform you need to target, you'll need to familiarize yourself with each API:

  • Win32:
    • MFC (the API is ugly by modern standards, but does encapsulate the main Win32 UI paradigms and APIs, such as Common Controls. However, be prepared for an uphill fight to support latter-day UI features, such as High-DPI, bi-directional text and high-quality 2D rendering. GDI/GDI+ is on the way out, which means using Direct2D - which is fun because MFC assumes GDI)
    • UWP/XAML: If your application can be sandboxed (and run only on Windows 10) then you should take a good look at UWP/XAML (it's all native, so the CLR is not involved).
    • WPF: Using WPF makes it easier to create a high-quality user-interface, if you're comfortable with your application taking a dependency on the .NET Framework and writing UI code in C# - however the visual aesthetic of un-skinned WPF apps took a nosedive with Windows 10 (i.e. they're ugly) and WPF's default control set is very aneamic - but if you have the means (i.e. time, money, people) then you can get great results - and as a bonus the XAML for WPF is generally portable to UWP.
  • macOS: Cocoa - you will have a hard time doing this in C++. If you're targeting macOS I strongly suggest writing your UI layer in Swift (or Objective-C if you have to) and then linking-in to the rest of your application code using C++ bridges.
  • Linux: As Linux is just a kernel the set of "native" widgets depends on the desktop environment of the user - but most desktop programs seem to use GTK. And if you're going to use GTK then you might as well use GTK's cross-platform features to support Windows and macOS.

In conclusion: it's difficult and a lot of work. :) - and explains why many software titles today (mid-2017) often built as web-applications either on the web directly (e.g. Facebook, StackOverflow, SalesForce) or hosted webviews using Electron (e.g. Slack, VS Code, Atom) or some other hosted-webiew (PhoneGap apps, Spotify, etc).

Dai
  • 141,631
  • 28
  • 261
  • 374