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
$9.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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

Shipping Address

Billing Address

Shipping Methods
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
Estimated delivery fee Deliver to Malaysia

Standard delivery 10 - 13 business days

$8.95

Premium delivery 5 - 8 business days

$45.95
(Includes tracking information)

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 Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Malaysia

Standard delivery 10 - 13 business days

$8.95

Premium delivery 5 - 8 business days

$45.95
(Includes tracking information)

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
$19.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
$199.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
$279.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 $ 152.97
Mastering Qt 5
$48.99
QT5 Blueprints
$54.99
Application Development with Qt Creator - Second Edition
$48.99
Total $ 152.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

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela