PyQt Button Selection

本秂侑毒 提交于 2020-01-30 01:39:34

问题


I have a PyQt GUI set up that has a selection of QPushButtons and a QLineEdit text box (among other things). The text box is set up so as to call a function upon returnPressed(). My problem is that when I click on the text box and put in text, one of the buttons becomes selected which means that when I press enter in the text box it activates both the button and the text box function.

Is there a way around this? Some way to stop any buttons from being selected while the text box is being edited?

The code is fairly long so I can't add it here but if there are any questions regarding layout or anything that may be relevant, please ask.

Thank you for any help you can offer


回答1:


From your question and comments, I'm guessing that the buttons and line-edit are in a QDialog, and that the selection/highlighting occurs due to the default/autoDefault property of buttons.

Normally, these properties will be set to False, but in a QDialog they are automatically set to True. The button that is the current default gets an additional frame drawn around it (even when it doesn't have the keyboard focus), and is activated whenever the return key is pressed.

You can of course prevent this behaviour by simply doing:

button.setDefault(False)
button.setAutoDefault(False)

for each button in the dialog.



来源:https://stackoverflow.com/questions/20085130/pyqt-button-selection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!