Book Image

Cross-Platform Development with Qt 6 and Modern C++

By : Nibedit Dey
Book Image

Cross-Platform Development with Qt 6 and Modern C++

By: Nibedit Dey

Overview of this book

Qt is a cross-platform application development framework widely used for developing applications that can run on a wide range of hardware platforms with little to no change in the underlying codebase. If you have basic knowledge of C++ and want to build desktop or mobile applications with a modern graphical user interface (GUI), Qt is the right choice for you. Cross-Platform Development with Qt 6 and Modern C++ helps you understand why Qt is one of the favorite GUI frameworks adopted by industries worldwide, covering the essentials of programming GUI apps across a multitude of platforms using the standard C++17 and Qt 6 features. Starting with the fundamentals of the Qt framework, including the features offered by Qt Creator, this practical guide will show you how to create classic user interfaces using Qt Widgets and touch-friendly user interfaces using Qt Quick. As you advance, you'll explore the Qt Creator IDE for developing applications for multiple desktops as well as for embedded and mobile platforms. You will also learn advanced concepts about signals and slots. Finally, the book takes you through debugging and testing your app with Qt Creator IDE. By the end of this book, you'll be able to build cross-platform applications with a modern GUI along with the speed and power of native apps.
Table of Contents (17 chapters)
1
Section 1: The Basics
6
Section 2: Cross-Platform Development
8
Section 3: Advanced Programming, Debugging, and Deployment

Managing events with an event filter

In this section, you will learn how to manage events and how to filter a specific event and perform a task. You can achieve event filtering by reimplementing event handlers and installing event filters. You can redefine what an event handler should do by subclassing the widget of interest and reimplementing that event handler.

Qt provides five different approaches for event processing, as follows:

  • Reimplementing a specific event handler, such as paintEvent()
  • Reimplementing the QObject::event() function
  • Installing an event filter on the QObject instance
  • Installing an event filter on the QApplication instance
  • Subclassing QApplication and reimplementing notify()

The following code handles the left mouse button click on a custom widget while passing all other button clicks to the base QWidget class:

void MyClass::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton...