Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. PyQt doesn't understand &

PyQt doesn't understand &

Scheduled Pinned Locked Moved Solved Language Bindings
28 Posts 6 Posters 10.0k 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 20 Feb 2018, 21:06 last edited by
    #2

    Hi,

    No it's not, the underline represent the accelerator you set by using the & sign in your action name.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    U L 2 Replies Last reply 21 Feb 2018, 09:22
    0
    • S SGaist
      20 Feb 2018, 21:06

      Hi,

      No it's not, the underline represent the accelerator you set by using the & sign in your action name.

      U Offline
      U Offline
      user4592357
      wrote on 21 Feb 2018, 09:22 last edited by
      #3

      @SGaist
      i know right, but as you can see, i've put & in action name and F isn't underlined

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 21 Feb 2018, 10:51 last edited by
        #4

        Sorry, I misread your sentence.

        Can you show the complete action creation ?

        What version of Qt are you using ?
        What version of PyQt ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        U 1 Reply Last reply 21 Feb 2018, 11:14
        0
        • S SGaist
          21 Feb 2018, 10:51

          Sorry, I misread your sentence.

          Can you show the complete action creation ?

          What version of Qt are you using ?
          What version of PyQt ?

          U Offline
          U Offline
          user4592357
          wrote on 21 Feb 2018, 11:14 last edited by
          #5

          @SGaist
          @SGaist

          FILE = '&File'
          NEW = '&New'
          ...
          file_menu = self.__menu_bar.addMenu(FILE)
          action = file_menu.addAction(NEW, self.__on_new)
          

          and i'm using PyQt5.

          J 1 Reply Last reply 21 Feb 2018, 11:55
          0
          • U user4592357
            21 Feb 2018, 11:14

            @SGaist
            @SGaist

            FILE = '&File'
            NEW = '&New'
            ...
            file_menu = self.__menu_bar.addMenu(FILE)
            action = file_menu.addAction(NEW, self.__on_new)
            

            and i'm using PyQt5.

            J Offline
            J Offline
            JonB
            wrote on 21 Feb 2018, 11:55 last edited by
            #6

            @user4592357
            Hmm, although I don't use them myself, I concur. My code is a little different:

            self.actionCases = QtWidgets.QAction("&Cases", self)
            ...
            self.toolbar = QToolBar()
            self.toolbar.addAction(self.actionCases)
            

            "&Cases" does not show the C underlined. "&&Cases" shows as &Cases, so it's doing some ampersand-parsing. I'm Linux. Maybe it's not supposed to do anything on Linux? What are you? I have to doubt whether this is a Python/PyQt issue...

            U 1 Reply Last reply 21 Feb 2018, 12:19
            0
            • J JonB
              21 Feb 2018, 11:55

              @user4592357
              Hmm, although I don't use them myself, I concur. My code is a little different:

              self.actionCases = QtWidgets.QAction("&Cases", self)
              ...
              self.toolbar = QToolBar()
              self.toolbar.addAction(self.actionCases)
              

              "&Cases" does not show the C underlined. "&&Cases" shows as &Cases, so it's doing some ampersand-parsing. I'm Linux. Maybe it's not supposed to do anything on Linux? What are you? I have to doubt whether this is a Python/PyQt issue...

              U Offline
              U Offline
              user4592357
              wrote on 21 Feb 2018, 12:19 last edited by
              #7

              @JonB
              i'm on windows

              1 Reply Last reply
              0
              • U Offline
                U Offline
                user4592357
                wrote on 21 Feb 2018, 18:42 last edited by
                #8

                there's another weird error that bothers me. whenever i import a class, for example:

                from PyQt5.QtCore import QObject
                

                i get this error:

                E0611:No name 'QObject' in module 'PyQt5.QtCore'
                

                same goes for all Qt classes.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 21 Feb 2018, 20:28 last edited by
                  #9

                  Then again: which version of PyQt5 and Qt 5 are you using ?
                  How did you installed them ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  U 1 Reply Last reply 22 Feb 2018, 06:06
                  1
                  • S SGaist
                    21 Feb 2018, 20:28

                    Then again: which version of PyQt5 and Qt 5 are you using ?
                    How did you installed them ?

                    U Offline
                    U Offline
                    user4592357
                    wrote on 22 Feb 2018, 06:06 last edited by user4592357
                    #10

                    @SGaist
                    Qt version: 5.10.0
                    SIP version: 5.10
                    PyQt version: 4.19.7

                    installed with pip3 install pyqt5

                    J 1 Reply Last reply 22 Feb 2018, 07:55
                    0
                    • U user4592357
                      22 Feb 2018, 06:06

                      @SGaist
                      Qt version: 5.10.0
                      SIP version: 5.10
                      PyQt version: 4.19.7

                      installed with pip3 install pyqt5

                      J Offline
                      J Offline
                      JonB
                      wrote on 22 Feb 2018, 07:55 last edited by JonB
                      #11

                      @user4592357

                      from PyQt5.QtCore import QObject
                      

                      This should indeed work for you. If it does not, I do not see how you can use any PyQt stuff at all! It is not related to the menu & issue.

                      I am:

                      PyQt version: 5.7
                      Qt version: 5.7.1
                      SIP version: 4.18.1
                      

                      Firstly, you say you are Qt 5.10 but PyQt 4.19. Therein lies your problem, for the imports at least. You must use a PyQt version matching your Qt version, and PyQt 4.x will not work for Qt version 5.x!!

                      (Gosh, I just noticed my own SIP is way behind yours. Doesn't seem to have hindered me anywhere. Does SIP version matter much?)

                      Secondly, you used pip3 to install PyQt. I had nothing but grief with pip3, and never used it. If you are saying you did a pip3 install pyqt5 and ended up with PyQt version 4.x, clearly something did not work correctly... Is it possible you have an older PyQt 4 lying around on your machine?

                      @SGaist
                      I would not mind a comment on why --- for me at least, with correct Qt 5 / PyQt 5 --- I do not get accelerator key visual or behaviour with &... menu item?

                      U 1 Reply Last reply 22 Feb 2018, 11:13
                      1
                      • J JonB
                        22 Feb 2018, 07:55

                        @user4592357

                        from PyQt5.QtCore import QObject
                        

                        This should indeed work for you. If it does not, I do not see how you can use any PyQt stuff at all! It is not related to the menu & issue.

                        I am:

                        PyQt version: 5.7
                        Qt version: 5.7.1
                        SIP version: 4.18.1
                        

                        Firstly, you say you are Qt 5.10 but PyQt 4.19. Therein lies your problem, for the imports at least. You must use a PyQt version matching your Qt version, and PyQt 4.x will not work for Qt version 5.x!!

                        (Gosh, I just noticed my own SIP is way behind yours. Doesn't seem to have hindered me anywhere. Does SIP version matter much?)

                        Secondly, you used pip3 to install PyQt. I had nothing but grief with pip3, and never used it. If you are saying you did a pip3 install pyqt5 and ended up with PyQt version 4.x, clearly something did not work correctly... Is it possible you have an older PyQt 4 lying around on your machine?

                        @SGaist
                        I would not mind a comment on why --- for me at least, with correct Qt 5 / PyQt 5 --- I do not get accelerator key visual or behaviour with &... menu item?

                        U Offline
                        U Offline
                        user4592357
                        wrote on 22 Feb 2018, 11:13 last edited by
                        #12

                        @JonB
                        i can use everything but pylint underlines the import lines.

                        and no, i installed Qt 5.10.1 then PyQt5 (using the command)

                        J 1 Reply Last reply 22 Feb 2018, 11:17
                        0
                        • U user4592357
                          22 Feb 2018, 11:13

                          @JonB
                          i can use everything but pylint underlines the import lines.

                          and no, i installed Qt 5.10.1 then PyQt5 (using the command)

                          J Offline
                          J Offline
                          JonB
                          wrote on 22 Feb 2018, 11:17 last edited by JonB
                          #13

                          @user4592357
                          So you are saying you are using PyQt 4.19.7 against Qt 5.10.0?
                          Plus, you did an install of pip3 install pyqt5 and you got PyQt 4.19.7?

                          If this really is the case, you should not be surprised that things don't work/appear right.

                          U 1 Reply Last reply 22 Feb 2018, 12:12
                          0
                          • J JonB
                            22 Feb 2018, 11:17

                            @user4592357
                            So you are saying you are using PyQt 4.19.7 against Qt 5.10.0?
                            Plus, you did an install of pip3 install pyqt5 and you got PyQt 4.19.7?

                            If this really is the case, you should not be surprised that things don't work/appear right.

                            U Offline
                            U Offline
                            user4592357
                            wrote on 22 Feb 2018, 12:12 last edited by
                            #14

                            @JonB
                            but why would that happen? (wrong installation)

                            J 1 Reply Last reply 22 Feb 2018, 12:20
                            0
                            • U user4592357
                              22 Feb 2018, 12:12

                              @JonB
                              but why would that happen? (wrong installation)

                              J Offline
                              J Offline
                              JonB
                              wrote on 22 Feb 2018, 12:20 last edited by JonB
                              #15

                              @user4592357
                              I don't know, 'coz like I said I never got on with pip3.

                              TBH, if you're saying you code actually works, I'd be surprised if it could run against PyQt4 at all. I wonder where you think you have PyQt 4 from in the first place? In my actual code I use from PyQt5.Qt import PYQT_VERSION_STR to get it, so you know what your code is actually using. And from PyQt5.QtCore import QT_VERSION_STR for Qt version.

                              U 1 Reply Last reply 22 Feb 2018, 12:30
                              0
                              • J JonB
                                22 Feb 2018, 12:20

                                @user4592357
                                I don't know, 'coz like I said I never got on with pip3.

                                TBH, if you're saying you code actually works, I'd be surprised if it could run against PyQt4 at all. I wonder where you think you have PyQt 4 from in the first place? In my actual code I use from PyQt5.Qt import PYQT_VERSION_STR to get it, so you know what your code is actually using. And from PyQt5.QtCore import QT_VERSION_STR for Qt version.

                                U Offline
                                U Offline
                                user4592357
                                wrote on 22 Feb 2018, 12:30 last edited by
                                #16

                                @JonB
                                i can't do anything using from PyQt4...

                                J 1 Reply Last reply 23 Feb 2018, 09:08
                                0
                                • K Offline
                                  K Offline
                                  KevinKSyd
                                  wrote on 23 Feb 2018, 05:06 last edited by KevinKSyd
                                  #17

                                  Not sure if this helps and it has nothing to do with the version of PyQt but in Windows you need to use the ALT key to bring up the underline letter used with the “&” symbol.

                                  It’s referenced in this SO question and answer

                                  1 Reply Last reply
                                  1
                                  • U user4592357
                                    22 Feb 2018, 12:30

                                    @JonB
                                    i can't do anything using from PyQt4...

                                    J Offline
                                    J Offline
                                    JonB
                                    wrote on 23 Feb 2018, 09:08 last edited by
                                    #18

                                    @user4592357
                                    Look, I really don't where you are. But If you used pip3 install pyqt5 and you got PyQt4 something is really wrong. And if it did get PyQt5 but somehow your code only finds PyQt4 you are equally in a mess. So you need to sort this out before you go any further....

                                    1 Reply Last reply
                                    0
                                    • K Offline
                                      K Offline
                                      KevinKSyd
                                      wrote on 23 Feb 2018, 13:54 last edited by
                                      #19

                                      He said he was using:

                                      SIP version: 5.10
                                      PyQt version: 4.19.7

                                      I think he just switched those two around and is confused. The most current version of SIP is 4.19.7 and the most current version of PyQt is 5.10. There never has been a version of PyQt4 with that version number nor has SIP gotten to that version number yet.

                                      1 Reply Last reply
                                      1
                                      • U Offline
                                        U Offline
                                        user4592357
                                        wrote on 23 Feb 2018, 16:27 last edited by user4592357
                                        #20

                                        i know it's hard to guess but it's 'she' :)

                                        btw this happens on my new laptop where i only installed qt 5.10.1 and then pyqt5.
                                        but the same happened also on my former laptop where i had qt4 and installed pyqt5.

                                        i have no idea what's going on

                                        anyways, i downloaded the sources and wannabuild. got the following:

                                        $ python configure.py
                                        Error: Use the --qmake argument to explicitly specify a working Qt qmake.
                                        
                                        python.exe .\configure.py --qmake C:\Qt\Qt5.10.1\5.10.1\msvc2015_64\bin\qmake
                                        .exe
                                        Querying qmake about your Qt installation...
                                        Determining the details of your Qt installation...
                                        Error: Failed to determine the detail of your Qt installation. Try again using
                                        the --verbose flag to see more detail about the problem.
                                        
                                        1 Reply Last reply
                                        0
                                        • S Offline
                                          S Offline
                                          SGaist
                                          Lifetime Qt Champion
                                          wrote on 23 Feb 2018, 21:09 last edited by
                                          #21

                                          What do you get if you make it verbose ?

                                          By the way, you may avoid much of the hassle by using pip/pip3 do install PyQt5.

                                          Interested in AI ? www.idiap.ch
                                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                          U 1 Reply Last reply 24 Feb 2018, 05:36
                                          0

                                          11/28

                                          22 Feb 2018, 07:55

                                          • Login

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