The combobox selections are sticky on the screen after I click the button
-
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.
Has anyone met the same problem? Is there any suggestion for me?
Really thanks!!!!
-
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 ? -
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 codesimport 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!
-
@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?
- In your code above is there anything in the
-
@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
And the code is belowimport 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!
-
@lazy26
If you (seem to) say that withplt.show()
you get the pop up and withoutplt.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.... -
@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 aQTimer::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. -
@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?
-
@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.