Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. How to Enable Python Type Hints in Qt Creator?
Qt 6.11 is out! See what's new in the release blog

How to Enable Python Type Hints in Qt Creator?

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
18 Posts 3 Posters 759 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • cristian-adamC Offline
    cristian-adamC Offline
    cristian-adam
    wrote last edited by cristian-adam
    #9

    I've opened up QTCREATORBUG-34195: Python debugging not having pretty printers for Pyside6 Qt types.

    cristian-adamC 1 Reply Last reply
    1
    • JonBJ JonB

      @cristian-adam
      It looks like your latest post crossed with mine! That again is an improvement to show the parameters, good. But still no type hint (the type expected for the on parameter), is that supported? :) And I don't know whether all the Qt calls are annotated in the PySide with their types, that may require a manual step?

      cristian-adamC Offline
      cristian-adamC Offline
      cristian-adam
      wrote last edited by
      #10

      @JonB said in How to Enable Python Type Hints in Qt Creator?:

      @cristian-adam
      It looks like your latest post crossed with mine! That again is an improvement to show the parameters, good. But still no type hint (the type expected for the on parameter), is that supported? :) And I don't know whether all the Qt calls are annotated in the PySide with their types, that may require a manual step?

      qt-creator-18-pyside-annotation.png

      It did mention that on is a bool, was that it?

      JonBJ 1 Reply Last reply
      2
      • cristian-adamC cristian-adam

        @JonB said in How to Enable Python Type Hints in Qt Creator?:

        @cristian-adam
        It looks like your latest post crossed with mine! That again is an improvement to show the parameters, good. But still no type hint (the type expected for the on parameter), is that supported? :) And I don't know whether all the Qt calls are annotated in the PySide with their types, that may require a manual step?

        qt-creator-18-pyside-annotation.png

        It did mention that on is a bool, was that it?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote last edited by JonB
        #11

        @cristian-adam said in How to Enable Python Type Hints in Qt Creator?:

        It did mention that on is a bool, was that it?

        That is indeed the chappie :) It also shows the function call returns None, which is a type hint too.

        Python decided not to have types initially. Then someone came to their senses and said "well we don't want mandatory types, but if you are finicky enough to want to type in types as hints we will let you do that". And then presumably someone said "these are really useful when editing, so we'll introduce warnings when they're wrong and editors can show them if they help people". :)

        1 Reply Last reply
        1
        • cristian-adamC cristian-adam

          I've opened up QTCREATORBUG-34195: Python debugging not having pretty printers for Pyside6 Qt types.

          cristian-adamC Offline
          cristian-adamC Offline
          cristian-adam
          wrote last edited by
          #12

          @cristian-adam said in How to Enable Python Type Hints in Qt Creator?:

          I've opened up QTCREATORBUG-34195: Python debugging not having pretty printers for Pyside6 Qt types.

          And as workaround for the missing debugger, is the qDebug() trace:

          from PySide6.QtCore import Qt, qDebug
          
          # ...
          
              qDebug("Label text: " + label.text())
          
          JonBJ 1 Reply Last reply
          0
          • cristian-adamC cristian-adam

            @cristian-adam said in How to Enable Python Type Hints in Qt Creator?:

            I've opened up QTCREATORBUG-34195: Python debugging not having pretty printers for Pyside6 Qt types.

            And as workaround for the missing debugger, is the qDebug() trace:

            from PySide6.QtCore import Qt, qDebug
            
            # ...
            
                qDebug("Label text: " + label.text())
            
            JonBJ Offline
            JonBJ Offline
            JonB
            wrote last edited by JonB
            #13

            @cristian-adam
            Alternatively as a workaround and still using the debugger panes rather than putting in a qDebug() statement, did you try putting label.text() into the bottom right Expressions pane?

            cristian-adamC 1 Reply Last reply
            0
            • JonBJ JonB

              @cristian-adam
              Alternatively as a workaround and still using the debugger panes rather than putting in a qDebug() statement, did you try putting label.text() into the bottom right Expressions pane?

              cristian-adamC Offline
              cristian-adamC Offline
              cristian-adam
              wrote last edited by
              #14

              @JonB said in How to Enable Python Type Hints in Qt Creator?:

              @cristian-adam
              Alternatively as a workaround and still using the debugger panes rather than putting in a qDebug() statement, did you try putting label.text() into the bottom right Expressions pane?

              qt-creator-18-debugger-expression.png

              Worked. I didn't give me Hello 🐍 but Hello =\d but I guess that's due to the missing UTF-8 encoding.

              1 Reply Last reply
              0
              • JonBJ Offline
                JonBJ Offline
                JonB
                wrote last edited by JonB
                #15

                I didn't notice you were printing a duck/swan thing, wth is that? :)

                Since (unlike C++) you can put pretty much any Python expression into Expressions, you might get it with something like label.text().encode('utf-8'), or label.text().decode('utf-8') if it's decoding rather than encoding, don't ask me about encodings!). In both PyQt and PySide all QStrings are translated into Python strs, which are those 16-bit encoding thingies.

                Just while we are here, I would give a limb if gdb/C++ Creator debugging would allow expressions to be evaluated in the Expressions pane. I understand the issue with C++ versus Python for expression evaluation, but it's the single most irritating thing when debugging C++.... :(

                cristian-adamC 2 Replies Last reply
                0
                • JonBJ JonB

                  I didn't notice you were printing a duck/swan thing, wth is that? :)

                  Since (unlike C++) you can put pretty much any Python expression into Expressions, you might get it with something like label.text().encode('utf-8'), or label.text().decode('utf-8') if it's decoding rather than encoding, don't ask me about encodings!). In both PyQt and PySide all QStrings are translated into Python strs, which are those 16-bit encoding thingies.

                  Just while we are here, I would give a limb if gdb/C++ Creator debugging would allow expressions to be evaluated in the Expressions pane. I understand the issue with C++ versus Python for expression evaluation, but it's the single most irritating thing when debugging C++.... :(

                  cristian-adamC Offline
                  cristian-adamC Offline
                  cristian-adam
                  wrote last edited by
                  #16

                  @JonB said in How to Enable Python Type Hints in Qt Creator?:

                  I didn't notice you were printing a duck/swan thing, wth is that? :)

                  🐍 https://emojipedia.org/snake

                  1 Reply Last reply
                  0
                  • JonBJ JonB

                    I didn't notice you were printing a duck/swan thing, wth is that? :)

                    Since (unlike C++) you can put pretty much any Python expression into Expressions, you might get it with something like label.text().encode('utf-8'), or label.text().decode('utf-8') if it's decoding rather than encoding, don't ask me about encodings!). In both PyQt and PySide all QStrings are translated into Python strs, which are those 16-bit encoding thingies.

                    Just while we are here, I would give a limb if gdb/C++ Creator debugging would allow expressions to be evaluated in the Expressions pane. I understand the issue with C++ versus Python for expression evaluation, but it's the single most irritating thing when debugging C++.... :(

                    cristian-adamC Offline
                    cristian-adamC Offline
                    cristian-adam
                    wrote last edited by
                    #17

                    @JonB said in How to Enable Python Type Hints in Qt Creator?:

                    Since (unlike C++) you can put pretty much any Python expression into Expressions, you might get it with something like label.text().encode('utf-8'), or label.text().decode('utf-8') if it's decoding rather than encoding, don't ask me about encodings!). In both PyQt and PySide all QStrings are translated into Python strs, which are those 16-bit encoding thingies.

                    label.text().decode('utf-8') results in <unavailable>.

                    🤷🏻‍♂️

                    JonBJ 1 Reply Last reply
                    0
                    • cristian-adamC cristian-adam

                      @JonB said in How to Enable Python Type Hints in Qt Creator?:

                      Since (unlike C++) you can put pretty much any Python expression into Expressions, you might get it with something like label.text().encode('utf-8'), or label.text().decode('utf-8') if it's decoding rather than encoding, don't ask me about encodings!). In both PyQt and PySide all QStrings are translated into Python strs, which are those 16-bit encoding thingies.

                      label.text().decode('utf-8') results in <unavailable>.

                      🤷🏻‍♂️

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote last edited by JonB
                      #18

                      @cristian-adam
                      encode works on strings, str or QString. decode works on bytes, bytes or QByteArray. That may explain <unavailable> on text().decode(). I told you I didn't understand :) If you had stuck to Hello world! we wouldn't be having this discussion ;-)

                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved