Willy's Reflections

| Willy-Peter Schaub | Visual Studio ALM Rangers | In search of IT simplicity, quality and tranquility |

UNISA Chatter – Design patterns in C++ Part 4: Widgets … getting started with the QT User Interface

UNISA Chatter – Design patterns in C++ Part 4: Widgets … getting started with the QT User Interface

  • Comments 2

See UNISA – Summary of 2010 Posts for a list of related UNISA posts. Continued from UNISA Chatter – UNISA Chatter – Design patterns in C++ Part 3: Generics & Serializer Pattern  .

QT and Environment Summary

The following is a summary of findings as I worked through the course related book. See the summary post for details on the book.

Terminology Description Example
QWidget

Class using multiple inheritance, as shown, making it paintable and an object that can have parents and all the other goodies shipped with QObject.

image

There are different classes of QWidgets:

  • Button
  • Input
  • Display
  • Container
  • QPushButton, QToolButton, QCheckBox, QRadioButton
  • QComboBox, QLineEdit, QTextEdit, QSlider, QTimeEdit, QDateEdit, QSpinButton, QScrollBar
  • QPixMap, QLabel, QProgressBar
  • QMainWindow, QFrame, QToolbar, QTabWidget, QStacketWidget, QFileDialog, QInputDialog, …
QMainWindow

QMainWindow is the mother of all windows, the main window, and therefore the parent of all other widgets in the main window. Most QApplication objects, we introduced in previous posts, manage one of these QMainWindow objects.

QSettings

QSettings is used to save and restore application state, using a persistent map of value and key pairs.

 
QMessageBox

Something that I am pondering over, but actually liking, is the apparent overlap and similarity with Win32 and .NET classes. The QMessageBox just brought back so many memories … it is used, as in the other mentioned environments, to popup a standard dialog.

QMessageBox::question(this,”if it is neither here nor there, where is it?”, “interesting”, 0, –1);
Images and Resources

To include binary files, such as images, in our Qt application we follow a few easy steps:

  1. Create a Resource Collection File (.qrc) that is an XML file that lists all of the binary files.
  2. Generate a resource file (rcc) using a Python script
  3. Add a RESOURCE line in the project file that defines the name of the qresource file.

… or we can simply use the IDE.

See the sample solution for examples.

Layout

To control the layout of the windows we can use the following classes, amongst others:

  • Layout (must have a QWidget or QLayout parent)
    • QVBoxLayout
    • QHBoxLayout
    • QGridLayout
    • QStackedLayout
  • Spacing (fixed number of pixles)
    • addSpacing
  • Stretch (stretchable number of pixles)
    • addStretch
  • Structs (minimum size of perpendicular dimension)
    • addStruct
  • Regions
    • QDockWidget
    • QSplitters

See the sample solution for examples.

Design Pattern Summary

Terminology Description
Pattern: Monostate
  • Creational design pattern
  • Allows multiple instances of an application to share the same one (mono) state.
  • It is an implementation of the Singleton pattern.
    image … the Visual Studio class diagram emerges :) Sanity prevails.
Pattern: Command
  • Behavioural design pattern
  • Encapsulates commands/operations  in as objects with a common interface, making it possible to operations, log operations and implement features such as undo, redo and transactions.
    image 

The will post the sample solution I developed as soon as I submit the assignment, which use most of the QT features summarised above. When I am done with UNISA, I will probably rewrite all of these samples using Visual Studio 2010 and demonstrate the phenomenal features and productivity of that environment as well.

Here are a few screen shots, which should highlight the favourite sample program emerging through the technology forest once again:
image image

image … 8! = 512 … it even works :)

I once had lots of fun writing the code and debugging the gremlins and odd behaviours using the QT IDE.  Not sure what the problem is, but there are often locked files, especially after a debug session, forcing an IDE restart … brings back memories from very early Visual Studio builds and can be rather tiring late at night.

Next post will explore the QVC pattern … a pattern that has also settled firmly in Visual Studio 2010 samples. If only we could complete these assignments using Visual Studio 2010 :|

  • Hi Willy, may I ask why you say that the Monostate pattern is a creational pattern rather than a structural pattern? I am might be very wrong (and then you will hopefully correct me), but the monostate pattern prescribes that all data members be static - meaning that the pattern describes something about the object's structure. Where object_state + object_methods = object_structure; thus altering state, means altering structure, thus structuaral pattern?  Thanks for posting your notes!

  • I slotted the MonoState into the creational category due to its similiarities with the Singletion pattern, which is also a creational pattern.

Page 1 of 1 (2 items)
Leave a Comment
  • Please add 4 and 2 and type the answer here:
  • Post