Creating a widget with Qt Creator/Designer

When we started working on Hello From Qt! in Chapter 2, Writing Your First Qt Application, we created our first widget, MainWindow:

MainWindow inherited from QMainWindow, which traces its ancestry back to QWidget. The Designer screen allowed us to populate MainWindow with different predefined widgets.

There are actually three files associated with MainWindow:

  • MainWindow.h defines the MainWindow C++ class
  • MainWindow.cc (or .cpp) provides the implementation of MainWindow
  • MainWindow.ui defines the graphic elements (widgets) that make up the display of MainWindow

What if we want to add a custom widget ...

Get Hands-On Embedded Programming with Qt now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.