pyside6[801-809]
pyside6[801-809]
(QtCore.Qt, 'Alignment'),
(QtCore.Qt, 'ApplicationAttribute'),
(QtCore.Qt, 'CheckState'),
(QtCore.Qt, 'CursorShape'),
(QtWidgets.QSizePolicy, 'Policy'),
]
Alternatively, you can define a custom function to handle the namespace lookup.
When passed an object and a PyQt6 compatible long-form name, this function
will return the correct enum or flag on both PyQt6 and PySide6.
If you’re doing this in multiple files it can get a bit cumbersome. A nice solution
to this is to move the import logic and custom shim methods to their own file, e.g.
named qt.py in your project root. This module imports the Qt modules (QtCore,
797
QtGui, QtWidgets, etc.) from one of the two libraries, and then you import into
your application from there.
import sys
if 'PyQt6' in sys.modules:
# PyQt6
from PyQt6 import QtGui, QtWidgets, QtCore
from PyQt6.QtCore import pyqtSignal as Signal, pyqtSlot as Slot
else:
# PySide6
from PySide6 import QtGui, QtWidgets, QtCore
from PySide6.QtCore import Signal, Slot
You must remember to add any other PyQt6 modules you use (browser,
multimedia, etc.) in both branches of the if block. You can then import Qt6 into
your own application as follows —
798
That’s really it
There’s not much more to say — the two libraries really are that similar.
However, if you do stumble across any other PyQt6/PySide6 examples or features
which you can’t easily convert, drop me a note.
799
Appendix D: What next?
This book covers the key things you need to know to start creating GUI
applications with Python. If you’ve made it here you should be well on your way
to create your own apps!
But there is still a lot to discover while you build your applications. To help with
this I post regular tips, tutorials and code snippets on the accompanying website.
Like this book all samples are MIT licensed and free to mix into your own apps.
You may also be interested in joining my Python GUI Academy where I have
video tutorials covering the topics in this book & beyond!
Thanks for reading, and if you have any feedback or suggestions please let me
know!
Documentation
Resource
Qt6 Documentation
Copyright
This book is ©2022 Martin Fitzpatrick. All code examples in this book are free to
use in your own programming projects without license.
800
45. Thank you
This book continues to be expanded and updated in response to reader feedback.
Thankyou to the following readers for their contributions, which helped make
this edition what it is!
• James Battat
• Alex Bender
• Andries Broekema
• Juan Cabanela
• Max Fritzler
• Olivier Girard
• Richard Hohlfield
• Cody Jackson
• John E Kadwell
• Jeffrey R Kennedy
• Gajendra Khanna
• Alex Lombardi
• Guido Tognan
If you have feedback or suggestions for future editions, please get in touch.
801
Index
A database, 347
Debian, 712
accelerator keys, 112
DecorationRole, 315
accept, 121
dialog box, 125
actions, 108
dialog buttons, 122
arguments, 11
dialogs, 118
B dismissed, 118
basedir, 42 document mode, 92
bitmap graphics, 379 drawLine, 384
bitmap image, 380 drawPoint, 385
bitwise, 653 drawRect, 391
drawRects, 391
C
drawRoundedRect, 391
C++, 5, 774
Cancel, 121 E
802
G MySQL, 378
GIL, 462
N
H numpy, 340
horizontally, 79
O
I OK, 121
icons, 238, 94
P
installer, 704
palettes, 229
InstallForge, 696
Pandas, 343
intercept events, 180
paths, 630
K PEP8, 5
PNG, 241
key sequence, 114
PostgreSQL, 378
keyboard shortcut, 114
processes, 462
L processEvents, 459
layouts, 66 pseudo-selectors, 282
Linux package, 712 PyInstaller, 667, 696, 712
PyQtGraph, 489, 571
M
pyside6-uic, 224, 224
main window, 14
matplotlib, 593 Q
803
QDialogButtonBox, 125 QSS, 246
QDoubleSpinBox, 57 QStackedLayout, 66
QEvent, 180 QStandardItemModel, 322
QFont, 398 QStyle, 240
QGridLayout, 66 Qt Creator, 191, 197, 220
QHBoxLayout, 66 Qt Designer, 191, 196, 219, 243, 66
QIcon, 238 Qt namespace, 104, 114, 184, 37, 647
QLabel, 35, 39 QTableView, 322
QLineEdit, 54 QTabWidget, 90
QListItem, 51 QThreadPool, 476
QListView, 304 QVBoxLayout, 66
QListWidget, 51 QWidget, 414, 65
QMouseEvent, 180
R
QPainter, 380, 412
QPalette, 229 reject, 121
QRC, 216
S
QRect, 391
setSizePolicy, 417
QRectF, 391
signals, 19, 29, 619, 621
QResource, 215
slots, 19, 29, 621
QRunnable, 476
SQL, 347
QSlider, 60
SQLite, 348
QSpinBox, 57
stacked, 79
QSqlQuery, 367
standardIcon, 239
QSqlQueryModel, 365
status tip, 97
QSqlRelation, 362
style sheets, 246
QSqlRelationalDelegate, 363
subclass, 121
QSqlRelationalTableModel, 361
subprocess, 560
QSqlTableModel, 350
804
SVG, 241
sys.argv, 658
system tray, 636
tabbed, 85
threads, 462
timer, 458
toggleable, 100
toggled, 102
toolbar, 103
toolbars, 94
triggered action, 96
Ubuntu, 712
vertically, 79
widget, 94
widgets, 33
window, 10
window decorations, 10
windowTitleChanged, 27
805