Qt4 no focus loss on clicking menubar

删除回忆录丶 提交于 2019-12-24 01:08:21

问题


I have a pyqt application where I have two QLineEdit fields which get data from a QDataWidgetMapper. I can edit the text in the fields and the change is commit on focus loss when I e.g. click in the other unselected field.

But if I edit the text and then click on the menubar and there on e.g. save, I won't have a focus loss and therefore my last entered data never reaches the model.

How can I get a focus loss on clicking on the menubar?


回答1:


For me, connecting to the QLineEdit.editingFinished signal works as expected. Which is to say, the signal is sent whenever return/enter is pressed, or the line-edit loses focus (which includes opening a menu, minimizing the window, closing the program, etc).

However, in the long-term, I think relying on this mechanism alone is a bad idea. To give one example of why this may be: what if you added keyboard shortcuts for your menu items at some point in the future? Activating the save-action via a keyboard shortcut isn't going to trigger a focus-change event...

So I would put in place a separate mechanism that can programmatically committ all pending changes before invoking the save-action.



来源:https://stackoverflow.com/questions/22082582/qt4-no-focus-loss-on-clicking-menubar

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