PyQt QLineEdit 和“粘贴"事件? [英] PyQt QLineEdit and 'paste' event?

查看:55
本文介绍了PyQt QLineEdit 和“粘贴"事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到处搜索,但找不到有关在 PyQt4 QLineEdit 中粘贴文本时触发插槽/事件的示例?

I searched everywhere but couldn't find an example on triggering a slot/event when text gets pasted in an PyQt4 QLineEdit ?

推荐答案

将以下代码添加到您的 MyForm 类:

Add the following code to your MyForm class:

内部 __init__()

self.ui.lineEdit_URL.textChanged.connect(self.valueChanged)

定义新方法:

def valueChanged(self, text):
     if QtGui.QApplication.clipboard().text() == text:
         self.pasteEvent(text)

定义另一个方法:

def pasteEvent(self, text):
    # this is your paste event, whenever any text is pasted in the
    # 'lineEdit_URL', this method gets called.
    # 'text' is the newly pasted text.

    print text

这篇关于PyQt QLineEdit 和“粘贴"事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆