Menu

Cannot assign format to QTextEdit.ExtraSelection

Help
2017-06-07
2017-06-08
  • David Brooks

    David Brooks - 2017-06-07

    Is this expected behaviour? Qt 5.6 and trunk PythonQt.

    >>> from PythonQt import QtGui
    >>> selection = QtGui.QTextEdit.ExtraSelection()
    >>> fmt = QtGui.QTextCharFormat()
    >>> selection.format
    QTextCharFormat (QTextFormat(QTextFormat::FormatType(2)) , at: 0x7f9b17a1c6e0)
    >>> fmt
    QTextCharFormat (QTextFormat(QTextFormat::FormatType(2)) , at: 0x7f9b192736e0)
    >>> selection.format = fmt
    ValueError: Called py_set_format(QTextCharFormat format) -> void with wrong arguments: (QTextCharFormat (QTextFormat(QTextFormat::FormatType(2)) , at: 0x7f9b192736e0),)
    
    During handling of the above exception, another exception occurred:
    
    SystemError: PyEval_EvalFrameEx returned a result with an error set
    

    Thanks.

     
  • Florian Link

    Florian Link - 2017-06-07

    That's strange. I am using Qt 5.6 / Python 2.7 and it works for me:

    py> selection.format = fmt
    py> selection.format 
    2017-06-07 17:06:25 Info: QTextCharFormat (QTextFormat(QTextFormat::FormatType(2)) , at: 0x0000000008995380)
    
     
  • David Brooks

    David Brooks - 2017-06-08

    I get this with Qt 5.6 / Python 3.5.

    Looking at the relevant code in a debugger, PythonQtCallSlot() appears to return failure if the slot has void result type. The following makes things work:

    diff --git a/src/PythonQtSlot.cpp b/src/PythonQtSlot.cpp
    index 711cb4a..adcdda6 100644
    --- a/src/PythonQtSlot.cpp
    +++ b/src/PythonQtSlot.cpp
    @@ -235,6 +235,7 @@ bool PythonQtCallSlot(PythonQtClassInfo* classInfo, QObject* objectToCall, PyObj
           }
         } else {
           result = NULL;
    +      ok = false;
         }
       }
       recursiveEntry--;
    @@ -256,7 +257,7 @@ bool PythonQtCallSlot(PythonQtClassInfo* classInfo, QObject* objectToCall, PyObj
         // NOTE: a return value can not pass the ownership to CPP, it would not make sense...
       }
       // NOTE: it is important to only return here, otherwise the stack will not be popped!!!
    -  return result || (directReturnValuePointer && *directReturnValuePointer);
    +   return ok && (returnValueParam.typeId == QMetaType::Void || result || (directReturnValuePointer && *directReturnValuePointer));
     }
    
     //-----------------------------------------------------------------------------------
    
     
  • Florian Link

    Florian Link - 2017-06-08

    Hm, are you using Python 3.x ? Because with Python 2.7 I can't reproduce your problem...

     
  • David Brooks

    David Brooks - 2017-06-08

    Yes, Python 3.5

     
  • Florian Link

    Florian Link - 2017-06-08

    Your fix is correct, but the strange thing is that I do not get the error message printed, as you do...

     
  • Florian Link

    Florian Link - 2017-06-08

    I fixed it on svn trunk.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.