Book Image

Learn Qt 5

By : Nicholas Sherriff
Book Image

Learn Qt 5

By: Nicholas Sherriff

Overview of this book

Qt is a mature and powerful framework for delivering sophisticated applications across a multitude of platforms. It has a rich history in the Linux world, is widely used in embedded devices, and has made great strides in the Mobile arena over the past few years. However, in the Microsoft Windows and Apple Mac OS X worlds, the dominance of C#/.NET and Objective-C/Cocoa means that Qt is often overlooked. This book demonstrates the power and flexibility of the Qt framework for desktop application development and shows how you can write your application once and deploy it to multiple operating systems. Build a complete real-world line of business (LOB) solution from scratch, with distinct C++ library, QML user interface, and QtTest-driven unit-test projects. This is a suite of essential techniques that cover the core requirements for most LOB applications and will empower you to progress from a blank page to shipped application.
Table of Contents (11 chapters)

Anchors

One slight problem with our wonderful new SplashView is that it doesn’t actually fill the window. Sure, we can change the 400 x 200 dimensions to 1024 x 768 so that it matches MasterView, but then what happens if the user resizes the window? Modern UI is all about responsive design—dynamic content that can adapt to the display it’s being presented on, so hard-coding properties appropriate for only one platform aren’t ideal. Fortunately, anchors come to our rescue.

Let’s put our trusty old scratchpad project to use and take a look at anchors in action.

Right-click on qml.qrc and add a new AnchorsDemo.qml QML file alongside the existing main.qml file in the scratchpad folder. Don’t worry about subfolders or .qrc prefixes, aliases, or any of that jazz.

Dip into main.cpp and load our new file instead of main.qml:

engine.load(QUrl(QStringLiteral...