覆盖失去焦点事件以保存和显示模型的lastE

2024-04-19 09:57:52 发布

您现在位置:Python中文网/ 问答频道 /正文

失去焦点后,如何覆盖QWidget的focusOutEvent来保存/提交并显示QSqlTablemodel的lastError?我想通知用户,如果有任何问题,保存模型,让他纠正或放弃更改。你知道吗

我尝试在QWidget上实现下面的代码,QWidget是tabControl中的一个选项卡,但当我关闭选项卡或导航到子/子选项卡时,它不会执行

def focusOutEvent(self,event):
    print("Losing focus now")
    self.model.submitAll()
    print(self.model.lastError().text())

Tags: 代码用户模型selfeventmodeldef选项卡
1条回答
网友
1楼 · 发布于 2024-04-19 09:57:52

focusOutEvent通常要求将focusPolicy设置为默认值Qt::NoFocus以外的值,以便接收焦点事件。你知道吗

The policy is Qt::TabFocus if the widget accepts keyboard focus by tabbing, Qt::ClickFocus if the widget accepts focus by clicking, Qt::StrongFocus if it accepts both, and Qt::NoFocus (the default) if it does not accept focus at all.

请参阅http://doc.qt.io/archives/qt-4.8/qwidget.html#focusOutEvent&;http://doc.qt.io/archives/qt-4.8/qwidget.html#focusPolicy-prop以了解有关此操作的详细信息。你知道吗

相关问题 更多 >