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 920 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 cristian-adam

    @MariX Is the screenshot below the thing that you wanted?

    qt-creator-18-pyside6.png

    In oder to achieve this I've:

    1. Went to Preferences > Python where I clicked on Python 3.13.12 then on the right the buttons: Make Default and then Generate Kit.

    2. New Project and then in Application (Qt for Python) selected Empty Application

    3. Pasted the content provided by gpt-oss with the prompt create a pyside6 application that has a window with a label "Hello 🐍" with a text size 18.

    After step 2 I've been asked by Qt Creator if I want to install Pyside6 and clicked yes, and it did its magic.

    I have little knowledge about Python, but it seems like code completion works.

    Here are the Python LSP settings:
    qt-creator-18-python-lsp.png

    The debugging helpers are not that ... helpful:
    qt-creator-18-python-debugging.png

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #4

    @cristian-adam
    Hi Christian. Since my time it seems that you are showing Python autocompletion, which is a start. But the OP asked for "type hints", a couple of times. Your screenshot shows nothing about that. Does it offer that? E.g. after you select setAlignment from the dropdown do you get any type hints (parameter type), like you would for C++?

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

      @MariX Is the screenshot below the thing that you wanted?

      qt-creator-18-pyside6.png

      In oder to achieve this I've:

      1. Went to Preferences > Python where I clicked on Python 3.13.12 then on the right the buttons: Make Default and then Generate Kit.

      2. New Project and then in Application (Qt for Python) selected Empty Application

      3. Pasted the content provided by gpt-oss with the prompt create a pyside6 application that has a window with a label "Hello 🐍" with a text size 18.

      After step 2 I've been asked by Qt Creator if I want to install Pyside6 and clicked yes, and it did its magic.

      I have little knowledge about Python, but it seems like code completion works.

      Here are the Python LSP settings:
      qt-creator-18-python-lsp.png

      The debugging helpers are not that ... helpful:
      qt-creator-18-python-debugging.png

      cristian-adamC Offline
      cristian-adamC Offline
      cristian-adam
      wrote on last edited by
      #5

      After re-opening the project Qt Creator asked me if I want to configure the LSP with type hints.

      qt-creator-18-pyside6-python-lsp.png

      The code completion looks different now.

      JonBJ cristian-adamC 2 Replies Last reply
      0
      • cristian-adamC cristian-adam

        After re-opening the project Qt Creator asked me if I want to configure the LSP with type hints.

        qt-creator-18-pyside6-python-lsp.png

        The code completion looks different now.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #6

        @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 1 Reply Last reply
        0
        • cristian-adamC cristian-adam

          After re-opening the project Qt Creator asked me if I want to configure the LSP with type hints.

          qt-creator-18-pyside6-python-lsp.png

          The code completion looks different now.

          cristian-adamC Offline
          cristian-adamC Offline
          cristian-adam
          wrote on last edited by
          #7

          Then F2 on setAlignment jumped to a file that has some declarations:

          qt-creator-18-pyside6-symbol-jump.png

          Equivalent to jumping to a header file in C++.

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

            Then F2 on setAlignment jumped to a file that has some declarations:

            qt-creator-18-pyside6-symbol-jump.png

            Equivalent to jumping to a header file in C++.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #8

            @cristian-adam Yep, getting better :)

            1 Reply Last reply
            1
            • cristian-adamC Offline
              cristian-adamC Offline
              cristian-adam
              wrote on 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 on 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 on 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 on 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 on 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 on 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 on 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 on 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 on 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 on 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