Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
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
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

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 : 9781784390761
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Mar 30, 2015
Length: 272 pages
Edition : 1st
Language : English
ISBN-13 : 9781784390761
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
Banner background image

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

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.