Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
QT5 Blueprints
QT5 Blueprints

QT5 Blueprints: Design, build, and deploy cross-platform GUI projects using the amazingly powerful Qt 5 framework

eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

QT5 Blueprints

Chapter 2. Building a Beautiful Cross-platform Clock

In this chapter, you will learn that Qt is a great tool to build cross-platform applications. A Qt/C++ clock example is used as a demonstration here. The topics covered in this chapter, which are listed here, are essential for any real-world applications. These are as follows:

  • Creating a basic digital clock
  • Tweaking the digital clock
  • Saving and restoring settings
  • Building on Unix platforms

Creating a basic digital clock

It's time to create a new project, so we will create a Qt Widgets application named Fancy_Clock.

Note

We won't utilize any Qt Quick knowledge in this chapter.

Now, change the window title to Fancy Clock or any other name that you like. Then, the main window UI needs to be tailored because the clock is displayed at the top of the desktop. The menu bar, status bar, and toolbar are all removed. After that, we need to drag an LCD Number widget into centralWidget. Next, change the layout of MainWindow to LayOut Horizontally in order to autoresize the subwidget. The last thing that needs to be done to the UI file is to change frameShape to NoFrame under the QFrame column in the property of lcdNumber. If you've done this right, you'll get a prototype of a digital clock, as shown here:

Creating a basic digital clock

In order to update the LCD number display repeatedly, we have to make use of the QTimer class to set up a timer that emits a signal repetitively. In addition to this...

Tweaking the digital clock

It's time to make this basic digital clock look more beautiful. Let's add something like a transparent background, which sits on top of the frameless window. Using a transparent background can deliver a fantastic visual effect. While the frameless window hides window decorations, including a border and the title bar, a desktop widget, such as a clock, should be frameless and displayed on top of the desktop.

To make our clock translucent, simply add the following line to the constructor of MainWindow:

setAttribute(Qt::WA_TranslucentBackground);

The effect of the WA_TranslucentBackground attribute depends on the composition managers on the X11 platforms.

A widget may have lots of attributes, and this function is used to switch on or switch off a specified attribute. It's turned on by default. You need to pass a false Boolean as the second argument to disable an attribute. The full list of Qt::WidgetAttribute can be found in the Qt Reference Documentation...

Saving and restoring settings

Although the clock can be moved, it won't restore its last position after restarting. In addition to this, we can give users some choices to adjust the clock's appearance, such as the font color. To make it work, we need the QSettings class, which provides platform-independent persistent settings. It needs a company or organization name and the name of an application. A typical QSettings object can be constructed by using this line:

QSettings settings("Qt5 Blueprints", "Fancy Clock");

Here, Qt5 Blueprints is the organization's name and Fancy Clock is the application's name.

The settings are stored in the system registry on Windows, while they are stored in the XML preferences files on Mac OS X and the INI text files on the other Unix operating systems, such as Linux. However, we do not usually need to be concerned with this, since QSettings provides high-level interfaces to manipulate the settings.

If we're going to...

Building on the Unix platforms

So far, we are still trapped with our applications on Windows. It's time to test whether our code can be built on other platforms. In this chapter, the code involved with only desktop operating systems, while we'll get a chance to build applications for mobile platforms later in this book. In terms of other desktop operating systems, there are plenty of them, and most of them are Unix-like. Qt officially supports Linux and Mac OS X, along with Windows. Hence, users of other systems, such as FreeBSD, may need to compile Qt from scratch or get prebuilt packages from their own communities. In this book, the Linux distribution Fedora 20 is used as a demonstration to introduce platform crossing. Please bear in mind that there are lots of desktop environments and theming tools on Linux, so don't be surprised if the user interface differs. Well, since you're curious, let me tell you that the desktop environment is KDE 4 with QtCurve, unifying...

Summary

In this chapter, information, including some tricks, about UI designing is included. Furthermore, there are basic yet useful cross-platform topics. Now, you're able to write an elegant Qt application in your favorite, and possibly already mastered, C++.

In the next chapter, we are going to learn how to write an application in Qt Quick. However, fear not; Qt Quick is even easier and, of course, quicker to develop.

Left arrow icon Right arrow icon

Description

If you are a programmer looking for a truly cross-platform GUI framework to help you save your time by side-stepping the incompatibility between different platforms and building applications using Qt 5 for multiple targets, then this book is most certainly intended for you. It is assumed that you have a basic programming experience of C++ and fundamental knowledge about Qt.

What you will learn

  • Create graphical user interface applications with a customized layout and widgets Explore how the Model-View-Controller architecture works and relevant classes in Qt Develop a configurable application that is able to save and restore its own settings Write both static and dynamic plugins for Qt Widgets and Qt Quick applications Convert your single-threaded application to a nonblocking application by moving part of the application to another thread Enable your applications to support other languages dynamically

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Mar 30, 2015
Length: 272 pages
Edition : 1st
Language : English
ISBN-13 : 9781784394615
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Mar 30, 2015
Length: 272 pages
Edition : 1st
Language : English
ISBN-13 : 9781784394615
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 115.97
Mastering Qt 5
€36.99
QT5 Blueprints
€41.99
Application Development with Qt Creator - Second Edition
€36.99
Total 115.97 Stars icon

Table of Contents

11 Chapters
1. Creating Your First Qt Application Chevron down icon Chevron up icon
2. Building a Beautiful Cross-platform Clock Chevron down icon Chevron up icon
3. Cooking an RSS Reader with Qt Quick Chevron down icon Chevron up icon
4. Controlling Camera and Taking Photos Chevron down icon Chevron up icon
5. Extending Paint Applications with Plugins Chevron down icon Chevron up icon
6. Getting Wired and Managing Downloads Chevron down icon Chevron up icon
7. Parsing JSON and XML Documents to Use Online APIs Chevron down icon Chevron up icon
8. Enabling Your Qt Application to Support Other Languages Chevron down icon Chevron up icon
9. Deploying Applications on Other Devices Chevron down icon Chevron up icon
10. Don't Panic When You Encounter These Issues Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(9 Ratings)
5 star 33.3%
4 star 55.6%
3 star 0%
2 star 0%
1 star 11.1%
Filter icon Filter
Top Reviews

Filter reviews by




Bill Armstrong Jul 13, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I was originally reluctant to buy this book because a lot of the advertising was poorly written, and I thought the book could be a pain to read. It must have had the services of an excellent editor because it is very easy to read and understand. The exposition is suitable for someone starting out in Qt 5, and there are lots of examples. A good choice.
Amazon Verified review Amazon
WEMPE Jan 26, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Ich steige gerade komplett neu in die Welt von Qt und C++ ein. Das Buch bietet ein schnellen Einstieg in die Welt von Qt. Viele Themen werden soweit angeschnitten, dass es leicht fällt die Richtung zu erkennen, in der man weiter forschen muss.
Amazon Verified review Amazon
Amazon Customer Jun 26, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
On time. No problems.
Amazon Verified review Amazon
AOT Nov 18, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
No me lo he leído entero, pero Qt5 está lleno de secretos, este libro os ahorrará tiempo! No es un reference guide universal.
Amazon Verified review Amazon
TB Jan 14, 2016
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
I've been working with C/C++ for a few years now, and with Qt for 1-2 years...mainly with Qt4 in embedded systems. I have a couple of the (very thorough) Qt4-based books that are available here on Amazon, and they are very good. In fact, they are almost TOO good from the standpoint that they nearly overwhelm you with information. But as reference material, they are extremely valuable. That being said however, when I saw that this book was dealing with Qt5 I wanted to go ahead and read it.I read both of the reviews posted previous to mine, before buying the book. Then I purchased the Kindle version of this book and worked through the first couple of chapters. I can definitely see the criticism(s) noted in Keith Peter's review. It's pretty apparent that this book did not have a good Technical Editor to go through it, because there are a number of simple errors that should NOT have made it through. For example in chapter 2, here's one such example:"...In other cases, we have to explicitly set the parent for a QObject child so that the parent can take over its ownership and manage the release of its memory. Hence, we pass the QObject parent, which is this, a MainWindow class to the constructor of QTimer."It's unfortunate that the author doesn't point out that the "this" pointer is a pointer to the instance of a class that is currently being referenced. In other words, "this" isn't a class...it's a pointer to an instance of a class.There are a number of similar such errors in the first two chapters, but overall the intent of the author is very good I think. But as I stated above, the book is in dire need of a good Technical Editor to go through and point this out to the author. I have served as a Technical Editor for a book on embedded systems, and it's not an easy task. It take many hours of work to go through a book such as this, but the result is well worth the effort.So overall I'll want to come back and revisit this review after finishing the book, but for now I would have to give it a 4-stars due to poor editing. I would have to agree with Keith on this point. I would also add that you really do need to have some C++ experience before working through this book, as that is assumed--and it would also be most helpful to know something about Qt (and Qt Creator) before reading this book. While it's not absolutely imperative that you have used Qt before, there are many times that the author chooses not to go into elaborate detail on a take he asks you to perform. If you are at least somewhat experienced with Qt Creator you will have little problem getting things accomplished--but you might struggle a little but if you've never used the IDE before. On the other hand it will make you dig more for the answer(s), so I suppose that's not all bad.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.