简体   繁体   English

将参数传递给用于QLineEdit Qt的eventFilter

[英]Passing parameters to eventFilter for QLineEdit Qt

I have a QLineEdit which I set an eventFilter using installEventFilter(this). 我有一个QLineEdit,它使用installEventFilter(this)设置了一个eventFilter。 Is it possible to pass in parameters to this eventFilter? 是否可以将参数传递给此eventFilter? For example, I want multiple QLineEdits to all call the same eventFilter, but I need to pass in a parameter in order to be able to tell which QLineEdit box caused the event to occur. 例如,我希望多个QLineEdits都调用同一个eventFilter,但是我需要传递一个参数,以便能够知道哪个QLineEdit框导致了事件的发生。

Thanks in advance! 提前致谢!

The sender object is already passed to eventFilter as first parameter. 发送者对象已作为第一个参数传递给eventFilter。 So you are able to determine which QLineEdit is dispatched like this: 因此,您可以像这样确定派发哪个QLineEdit:

bool eventFilter(QObject *obj, QEvent *ev) {
    if (obj == lineEdit1) {
        // event from lineEdit1
    } else if (obj == lineEdit2) {
        // event from lineEdit2
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM