Qt5 Python GUI Programming Cookbook
Building responsive and powerful cross-platform applications with PyQt
B.M. Harwani
BIRMINGHAM - MUMBAI
Qt5 Python GUI Programming Cookbook
Copyright 2018 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Richa Tripathi
Acquisition Editor: Alok Dhuri
Content Development Editor: Zeeyan Pinheiro
Technical Editor: Vibhuti Gawde
Copy Editor: Safis Editing
Project Coordinator: Vaidehi Sawant
Proofreader: Safis Editing
Indexer: Rekha Nair
Graphics: Jason Monteiro
Production Coordinator: Nilesh Mohite
First published: July 2018
Production reference: 1270718
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78883-100-0
www.packtpub.com
I am thankful to my familymy small world: Anushka (my wife) and
my two little darlings, Chirag and Naman, for allowing me to work on
the book even during time that I was supposed to spend with them.
mapt.io
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details.
At www.PacktPub.com , you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Contributors
About the author
B.M. Harwani is the founder and owner of Microchip Computer Education (MCE), based in Ajmer, India. He graduated with a BE in computer engineering from the University of Pune and also has a C level (masters diploma in computer technology) from DOEACC, Government of India. Having been involved in the teaching field for over 20 years, he has developed the art of explaining even the most complicated topics in a straightforward and easily understandable fashion. He is also a renowned speaker and the author of several books. To learn more, visit his blog, a site that helps programmers.
A big thank you to the entire editorial team at Packt, who worked tirelessly to produce this book. Really, I enjoyed working with each of you.
I should not forget to thank my dear students, who have been a good teacher for me as they make me understand the basic problems they face in a subject and enable me to directly hit those topics. The endless interesting queries from my students help me write books with a practical approach.
About the reviewers
Marcus Ottosson is a company director, software developer, and artist with a decade of experience in the film and visual effects industry. He has built countless user interfaces and tools with Python and Qt for projects such as Marvels Doctor Strange and Alfonso Cuarons Gravity. He has written several Python frameworks for use in the creation of film and games, such as Pyblish and Avalon, along with PyQt, a compatibility wrapper around all the available bindings of Qt for Python.
Sivan Grnberg has close to 20 years of multidisciplinary IT expertise and a razor-sharp eye for quality. A long-time open source devotee, his contributions can be found, literally, all over open source. He has been utilizing the Python ecosystem for R&D endeavors ever since it was pitched to him by The SABDFL and Ubuntu. Alongside Shir, a product, content, and operations expert, he runs Vitakka.co, providing infrastructure consulting and coding solutions in all-things digital.
My amazing family, Eric, Helena, Shir, Moshik, and the Debian/Ubuntu, Python, GNOME, and KDE communitieswithout you, these lines would have never been written.
Packt is searching for authors like you
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Table of Contents
Preface
PyQt is one of the best cross-platform interface toolkits currently available; it's stable, mature, and completely native. If you want control over all aspects of UI elements, PyQt is what you need. This book will guide you through every concept you need to create fully functional GUI applications using PyQT, with only a few lines of code.
As you expand your GUI using more widgets, you will cover networks, databases, and graphical libraries that greatly enhance its functionality. The book shows you how to use QT Designer to design user interfaces and implement and test dialogs, events, the clipboard, and drag and drop functionality to customize your GUI. You will learn a variety of topics, such as look and feel customization, GUI animation, graphics rendering, implementing Google Maps, and more. Lastly, the book takes you through how Qt5 can help you create cross-platform apps that are compatible with Android and iOS. You will be able to develop functional and appealing software using PyQt through interesting and fun recipes that will expand your knowledge of GUIs.
Who this book is for
This book is meant for intermediate to advanced programmers and developers who have some preliminary knowledge of Python programming. This book can be of great use for trainers, teachers, and software developers who wish to build a fully-featured GUI-based application in Python.