Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. The combobox selections are sticky on the screen after I click the button

The combobox selections are sticky on the screen after I click the button

Scheduled Pinned Locked Moved Unsolved Qt for Python
11 Posts 3 Posters 1.5k 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.
  • L Offline
    L Offline
    lazy26
    wrote on last edited by
    #1

    Hi, everyone. I met a problem when I developed an interface using PyQt5 on mac.

    I have several combo boxes and several buttons in the UI. The problem is After I choose from a combo box and then click any pushbutton. The combo items will appear again and I cannot remove them unless I click the same combo box again.

    Like this. After I select the format from RST to XLSX and click start, the combo items appear and I can not remove that.
    fc827883-3d8b-4e16-bf98-5e94626dae08-image.png

    Has anyone met the same problem? Is there any suggestion for me?

    Really thanks!!!!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Which version of PyQt5 ?
      How did you install it ?
      Which version of macOS ?
      Which architecture ?
      Can you provide a minimal sample script that triggers this behaviour ?

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

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lazy26
        wrote on last edited by
        #3

        Hello.

        the version of PyQt 5 is 5.15.6;
        I installed it using pip install;
        The macOS is the macOS Monterey 12.3
        I think the trigger of the combo box re-appearance is I have to use the python library matplotlib to show some plots. These are some essential codes

        import matplotlib.pyplot as plt
        self.formatTypes = {"RST": 1, "TXT": 2, "XLSX": 3, "TIFF": 4}
        self.file_format_comboBox.addItems(self.formatTypes.keys())
        
        self.start_pushbutton.clicked.connect(self.start_TOC)
        def start_TOC(self):
             .........
             plt.show()
        

        Please let me know if you need more information! Thanks in advance!

        JonBJ 1 Reply Last reply
        0
        • L lazy26

          Hello.

          the version of PyQt 5 is 5.15.6;
          I installed it using pip install;
          The macOS is the macOS Monterey 12.3
          I think the trigger of the combo box re-appearance is I have to use the python library matplotlib to show some plots. These are some essential codes

          import matplotlib.pyplot as plt
          self.formatTypes = {"RST": 1, "TXT": 2, "XLSX": 3, "TIFF": 4}
          self.file_format_comboBox.addItems(self.formatTypes.keys())
          
          self.start_pushbutton.clicked.connect(self.start_TOC)
          def start_TOC(self):
               .........
               plt.show()
          

          Please let me know if you need more information! Thanks in advance!

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

          @lazy26 said in The combobox selections are sticky on the screen after I click the button:

          I think the trigger of the combo box re-appearance is I have to use the python library matplotlib to show some plots.

          I do not see why those should be connected. Really the only reason ought to be if something clicks on the combo box (or explicitly asks it to pop open, but that should not be the case). I don't know whether maybe setting focus to the combo box would make it show. Does anything in your own code do anything like that to the combo box, e.g. after a button click?

          • In your code above is there anything in the ... code which could cause this? Can you test commenting out all that code?
          • If you comment out just the plt.show() does that mean the combo does not pop up any longer?
          L 1 Reply Last reply
          0
          • JonBJ JonB

            @lazy26 said in The combobox selections are sticky on the screen after I click the button:

            I think the trigger of the combo box re-appearance is I have to use the python library matplotlib to show some plots.

            I do not see why those should be connected. Really the only reason ought to be if something clicks on the combo box (or explicitly asks it to pop open, but that should not be the case). I don't know whether maybe setting focus to the combo box would make it show. Does anything in your own code do anything like that to the combo box, e.g. after a button click?

            • In your code above is there anything in the ... code which could cause this? Can you test commenting out all that code?
            • If you comment out just the plt.show() does that mean the combo does not pop up any longer?
            L Offline
            L Offline
            lazy26
            wrote on last edited by
            #5

            @JonB Thanks, Jon

            I think the plt.show() is the problem. I wrote a simple code (only a combobox and pushbutton). After I select an item from the combobox and click start button. It shows
            cacaaebc-4868-44ee-b4d9-ff68a9776f06-image.png
            And the code is below

            import sys
            import matplotlib.pyplot as plt
            
            from PyQt5.QtWidgets import QApplication, QHBoxLayout, QPushButton, QWidget, QComboBox
            
            def draw_plt():
                # x axis values
                x = [1, 2, 3]
                # corresponding y axis values
                y = [2, 4, 1]
            
                # plotting the points
                plt.plot(x, y)
            
                # naming the x axis
                plt.xlabel('x - axis')
                # naming the y axis
                plt.ylabel('y - axis')
            
                # giving a title to my graph
                plt.title('My first graph!')
            
                # function to show the plot
                plt.show()
            
            
            app = QApplication(sys.argv)
            window = QWidget()
            window.setWindowTitle('combobox_test')
            layout = QHBoxLayout()
            combobox_1 = QComboBox()
            combobox_1.addItems(['RST','TXT','XLSX', 'TIF'])
            pushbutton_1 = QPushButton('start')
            pushbutton_1.clicked.connect(draw_plt)
            
            layout.addWidget(combobox_1)
            layout.addWidget(pushbutton_1)
            window.setLayout(layout)
            window.show()
            sys.exit(app.exec_())
            

            I don't know whether it connects to the combobox. However, I can only make the sticky combo box disappear by clicking the combo box again.

            Does anything in your own code do anything like that to the combo box, e.g. after a button click? I only find the plt.show( would trigger combo box.

            Thanks for your prompt reply. Please let me know if you need more info or have some thoughts about this!

            JonBJ 1 Reply Last reply
            0
            • L lazy26

              @JonB Thanks, Jon

              I think the plt.show() is the problem. I wrote a simple code (only a combobox and pushbutton). After I select an item from the combobox and click start button. It shows
              cacaaebc-4868-44ee-b4d9-ff68a9776f06-image.png
              And the code is below

              import sys
              import matplotlib.pyplot as plt
              
              from PyQt5.QtWidgets import QApplication, QHBoxLayout, QPushButton, QWidget, QComboBox
              
              def draw_plt():
                  # x axis values
                  x = [1, 2, 3]
                  # corresponding y axis values
                  y = [2, 4, 1]
              
                  # plotting the points
                  plt.plot(x, y)
              
                  # naming the x axis
                  plt.xlabel('x - axis')
                  # naming the y axis
                  plt.ylabel('y - axis')
              
                  # giving a title to my graph
                  plt.title('My first graph!')
              
                  # function to show the plot
                  plt.show()
              
              
              app = QApplication(sys.argv)
              window = QWidget()
              window.setWindowTitle('combobox_test')
              layout = QHBoxLayout()
              combobox_1 = QComboBox()
              combobox_1.addItems(['RST','TXT','XLSX', 'TIF'])
              pushbutton_1 = QPushButton('start')
              pushbutton_1.clicked.connect(draw_plt)
              
              layout.addWidget(combobox_1)
              layout.addWidget(pushbutton_1)
              window.setLayout(layout)
              window.show()
              sys.exit(app.exec_())
              

              I don't know whether it connects to the combobox. However, I can only make the sticky combo box disappear by clicking the combo box again.

              Does anything in your own code do anything like that to the combo box, e.g. after a button click? I only find the plt.show( would trigger combo box.

              Thanks for your prompt reply. Please let me know if you need more info or have some thoughts about this!

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

              @lazy26
              If you (seem to) say that with plt.show() you get the pop up and without plt.show() you do not then indeed that seems the (peculiar) cause, however odd!

              I wonder whether it might be because the combo is the first widget in the window where you press the start button from, and somehow showing the plot causes that to (re-)receive focus. This may sound odd, but just try: put a "dummy", say, QLineEdit (something which accepts focus) as the first widget on your combobox_test widget, immediately to the left of the combobox. Just do it! Does that perchance gain focus after clicking the button and avoid the combo pop up? One in a thousand chance....

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lazy26
                wrote on last edited by
                #7

                Thanks, Jon. I tried your method. But it still has the same problem. Here is the screenshot. After I selected the item form combobox, the focus will go to lineedit. However, when I click the pushbutton, the combo selection shows again.
                6496c740-1d88-49d7-9bf3-96658ef2d953-image.png

                JonBJ 1 Reply Last reply
                0
                • L lazy26

                  Thanks, Jon. I tried your method. But it still has the same problem. Here is the screenshot. After I selected the item form combobox, the focus will go to lineedit. However, when I click the pushbutton, the combo selection shows again.
                  6496c740-1d88-49d7-9bf3-96658ef2d953-image.png

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

                  @lazy26
                  Well obviously this isn't supposed to happen! Maybe pyplot, maybe Mac, maybe if you only have a combobox, who knows.

                  You could subclass your combo so that you can put debugger breakpoints on whichever virtual methods to see if you can tell where it is being called to pop up from, and do something about that if you find anything useful.

                  To workaround: you might disable or hide the combo when you're about to call the plt.show(), and put a QTimer::singleShot() to re-enable/show it after a tiny delay. Something to make it so there is no combobox available for pyplot to mess with when it starts up.

                  L 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @lazy26
                    Well obviously this isn't supposed to happen! Maybe pyplot, maybe Mac, maybe if you only have a combobox, who knows.

                    You could subclass your combo so that you can put debugger breakpoints on whichever virtual methods to see if you can tell where it is being called to pop up from, and do something about that if you find anything useful.

                    To workaround: you might disable or hide the combo when you're about to call the plt.show(), and put a QTimer::singleShot() to re-enable/show it after a tiny delay. Something to make it so there is no combobox available for pyplot to mess with when it starts up.

                    L Offline
                    L Offline
                    lazy26
                    wrote on last edited by
                    #9

                    @JonB Thank, Jon.

                    I was trying to find some signal after I use the plt.show(), but I didn't figure it out.

                    But I found something interesting.

                    The trigger of the sticky combo selection is:
                    click combo box -> click any item in the selection list -> plt.show()

                    But if I follow the steps:
                    click combo box -> click any item in the selection list -> click combo box (the selection list appears) ->click combobox (without selecting anything and the selection list folded) -> plt.show()

                    The sticky combo box selection doesn't show.

                    Is this helpful for you to find out the reason why this happens?

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      lazy26
                      wrote on last edited by
                      #10

                      I also tried the code in the windows system. And, there is no similar problem in windows.

                      I think the mac os system may not be compatible with the PyQt5 in some way.

                      JonBJ 1 Reply Last reply
                      0
                      • L lazy26

                        I also tried the code in the windows system. And, there is no similar problem in windows.

                        I think the mac os system may not be compatible with the PyQt5 in some way.

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

                        @lazy26 said in The combobox selections are sticky on the screen after I click the button:

                        I think the mac os system may not be compatible with the PyQt5 in some way.

                        PyQt5 is only a Python binding around Qt5. The issue will be in Qt5. It's not that it's "not compatible" with Mac OS, it will be that occasionally there are some behaviours which differ across platforms/windowing systems. They may be "bugs" or "glitches" or "features". If it's also all tied up with using matplotlib.pyplot goodness knows where the issue might be.

                        1 Reply Last reply
                        0

                        • Login

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