Search code examples
qtpysidediagram

Working PySide example of Qt diagram editor?


When running the PySide Diagram Scene example (circa 2010), I get the error below. Is there a more current example of a basic diagram editor available?

C:\Python34\python.exe C:/Users/dle/Documents/Programming/Python/diagramscene.py
Traceback (most recent call last):
  File "C:/Users/dle/Documents/Programming/Python/diagramscene.py", line 11, in <module>
import diagramscene_rc
  File "C:\Users\dle\Documents\Programming\Python\diagramscene_rc.py", line 404, in <module>
qInitResources()
  File "C:\Users\dle\Documents\Programming\Python\diagramscene_rc.py", line 399, in qInitResources
QtCore.qRegisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
TypeError: 'qRegisterResourceData' called with wrong argument types:
  qRegisterResourceData(int, str, str, str)
Supported signatures:
  qRegisterResourceData(int, unicode, unicode, unicode)

Solution

  • The problem is that the file diagramscene_rc.py has been generated for python2, to solve it you must recompile that file for it opens a terminal in the folder and executes the following command:

    pyside-rcc diagramscene.qrc -o diagramscene_rc.py -py3
    

    Or, place the letter b before assigning the variable as shown below:

    qt_resource_data = "\
    \x00\x00\x01\x12\ 
    ...
    qt_resource_name = "\
    \x00\x06\
    ...
    qt_resource_struct = "\
    \x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\
    ....
    

    to:

    qt_resource_data = b"\
    \x00\x00\x01\x12\ 
    ...
    qt_resource_name = b"\
    \x00\x06\
    ...
    qt_resource_struct = b"\
    \x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\
    ....