Qt5 Python GUI Programming Cookbook
Building responsive and powerful cross-platform applications with PyQt
B.M. Harwani
- 462 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Qt5 Python GUI Programming Cookbook
Building responsive and powerful cross-platform applications with PyQt
B.M. Harwani
About This Book
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.
Frequently asked questions
Information
Event Handling - Signals and Slots
- 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
Using Signal/Slot Editor
How to do it...
- 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.
- 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.
- To cancel the connection while dragging the mouse, simply press the Esc key.
- 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.
- After selecting the respective signal and slot, select OK to establish the signal and slot connection.
- 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:
- When connected, the selected signal and slot will appear as labels in the arrow, connecting the two widgets.
- To modify a signal and slot connection, double-click the connection path or one of its labels to display the Configure Connection dialog box.
- From the Configure Connection dialog, you can edit a signal or a slot as desired.
- To delete a signal and slot connection, select its arrow on the form and press the Delete key.
- 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.
- 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
Getting ready
- 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 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...
- Select the Edit Signals/Slots icon from the toolbar to switch to signals and slots editing mode.
- 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...