I'm trying to learn more about using QGIS Map Canvas widgets and creating custom map tools, so the information from the PyQGIS cookbook is very helpful. After trying to experiment with mywnd.py from this page: https://www.qgis.org/en/docs/pyqgis_developer_cookbook/canvas.html I had a few difficulties.
On first try running the script, I got ImportError: cannot import name QString. To overcome this error I imported like so:
try: from PyQt4.QtCore import SIGNAL, Qt, QString except ImportError: QString = str
That allowed me to get through the import. However, after inputting the following lines into the python console as directed by the cookbook, I got NameError: global name 'QString' is not defined
w = mywnd.MyWnd(qgis.utils.iface.activeLayer())