Qt5 Python GUI Programming Cookbook
eBook - ePub

Qt5 Python GUI Programming Cookbook

Building responsive and powerful cross-platform applications with PyQt

B.M. Harwani

Partager le livre
  1. 462 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et Android
eBook - ePub

Qt5 Python GUI Programming Cookbook

Building responsive and powerful cross-platform applications with PyQt

B.M. Harwani

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

À propos de ce livre

Over 60 recipes to help you design interactive, smart, and cross-platform GUI applications

Key Features

  • Get succinct QT solutions to pressing GUI programming problems in Python
  • Learn how to effectively implement reactive programming
  • Build customized applications that are robust and reliable

Book Description

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 necessary 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. Next, the book guides you in using Qt Designer to design user interfaces and implementing and testing 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 to 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

What you will learn

  • Use basic Qt components, such as a radio button, combo box, and sliders
  • Use QSpinBox and sliders to handle different signals generated on mouse clicks
  • Work with different Qt layouts to meet user interface requirements
  • Create custom widgets and set up customizations in your GUI
  • Perform asynchronous I/O operations and thread handling in the Python GUI
  • Employ network concepts, internet browsing, and Google Maps in UI
  • Use graphics rendering and implement animation in your GUI
  • Make your GUI application compatible with Android and iOS devices

Who this book is for

If you're an intermediate Python programmer wishing to enhance your coding skills by writing powerful GUIs in Python using PyQT, this is the book for you.

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que Qt5 Python GUI Programming Cookbook est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  Qt5 Python GUI Programming Cookbook par B.M. Harwani en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Informatique et Programmation en Python. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Année
2018
ISBN
9781788830461
Édition
1

Event Handling - Signals and Slots

In this chapter, we will learn about the following topics:
  • Using Signal/Slot Editor
  • Copying and pasting text from one Line Edit widget to another
  • Converting data types and making a small calculator
  • Using the Spin Box widget
  • Using scrollbars and sliders
  • Using List Widget
  • Selecting multiple list items from one List Widget and displaying them in another
  • Adding items into List Widget
  • Performing operations in List Widget
  • Using the Combo Box widget
  • Using the Font Combo Box widget
  • Using the Progress Bar widget

Introduction

Event handling is an important mechanism in every application. The application should not only recognize the event, but must take the respective action to serve the event, too. The action taken on any event determines the course of the application. Each programming language has a different technique for handling or listening to events. Let's see how Python handles its events.

Using Signal/Slot Editor

In PyQt, the event handling mechanism is also known as signals and slots. An event can be in the form of clicking or double-clicking on a widget, or pressing the Enter key, or selecting an option from a radio button, checkbox, and so on. Every widget emits a signal when any event is applied on it and, that signal needs to be connected to a method, also known as a slot. A slot refers to the method containing the code that you want to be executed on the occurrence of a signal. Most widgets have predefined slots; you don't have to write code to connect a predefined signal to a predefined slot.
You can even edit a signal/slot by navigating to the Edit | Edit Signals/Slots tool in the toolbar.

How to do it...

To edit the signals and slots of different widgets placed on the form, you need to switch to signals and slots editing mode by performing the following steps:
  1. You can press the F4 key, navigate to the Edit | Edit Signals/Slots option, or select the Edit Signals/Slots icon from the toolbar. The mode displays all the signal and slot connections in the form of arrows, indicating the connection of a widget with its respective slot.
You can also create new signal and slot connections between widgets in this mode and delete an existing signal.
  1. To establish a signal and slot connection between two widgets in a form, select a widget by left-clicking the mouse on the widget, dragging the mouse towards another widget to which you want to connect, and releasing the mouse button over it.
  2. To cancel the connection while dragging the mouse, simply press the Esc key.
  3. On releasing the mouse over the destination widget, a Connection Dialog box appears, prompting you to select a signal from the source widget and a slot from the destination widget.
  4. After selecting the respective signal and slot, select OK to establish the signal and slot connection.
The following screenshot shows dragging a Push Button over a Line Edit widget:
  1. On releasing the mouse button on the Line Edit widget, you get the list of predefined signals and slots, as shown in the following screenshot:
You can also select Cancel in the Configure Connection dialog box to cancel the signal and slot connection.
  1. When connected, the selected signal and slot will appear as labels in the arrow, connecting the two widgets.
  2. To modify a signal and slot connection, double-click the connection path or one of its labels to display the Configure Connection dialog box.
  3. From the Configure Connection dialog, you can edit a signal or a slot as desired.
  4. To delete a signal and slot connection, select its arrow on the form and press the Delete key.
The signal and slot connection can also be established between any widget and the form. To do so, you can perform the following steps:
  1. Select the widget, drag the mouse, and release the mouse button over the form. The end point of the connection changes to the electrical ground symbol, representing that a connection has been established with the form.
  2. To come out of signal and slot editing mode, navigate to Edit | Edit Widgets or press the F3 key.

Copying and pasting text from one Line Edit widget to another

This recipe will make you understand how an event performed on one widget invokes a predefined action on the associated widget. Because we want to copy content from one Line Edit widget on clicking the push button, we need to invoke the selectAll() method on the occurrence of the pressed() event on push button. Also, we need to invoke the copy() method on occurrence of the released() event on the push button. To paste the content in the clipboard into another Line Edit widget on clicking of another push button, we need to invoke the paste() method on the occurrence of the clicked() event on another push button.

Getting ready

Let's create an application that consists of two Line Edit and two Push Button widgets. On clicking the first push button, the text in the first Line Edit widget will be copied and on clicking the second push button, the text copied from the first Line Edit widget will be pasted onto the second Line Edit widget.
Let's create a new application based on the Dialog without Buttons template by performing the following steps:
  1. Begin by adding QLineEdit and QPushButton to the form by dragging and dropping the Line Edit and Push Button widgets from the Widget box on the form.
To preview a form while editing, select either Form, Preview, or use Ctrl + R .
  1. To copy the text of the Line Edit widget when the user selects the push button on the form, you need to connect the push button's signal to the slot of Line Edit. Let's learn how to do it.

How to do it...

Initially, the form is in widget editing mode, and to apply signal and slot connections, you need to first switch to signals and slots editing mode:
  1. Select the Edit Signals/Slots icon from the toolbar to switch to signals and slots editing mode.
  1. On the form, select the push button, drag the mouse to the Line Edit widget, and release the mouse button. The Configure Connection dialog will pop up, allowing you to establish a signal and slot connection between the Push Button and the Line Edit...

Table des matiĂšres