擅长:python、mysql、java
<p>不能“monkey patch”<code>QLineEdit.paste()</code>的原因是它不是一个<em>虚拟的</em>函数。关于虚函数的重要一点是,当它们被重写时,重新实现的函数将由Qt在内部调用;而非虚重写只会由Python代码调用。因此,由于<code>QLinedit.paste()</code>不是虚拟的,您将不得不截获所有通常导致Qt在内部调用的<em>事件</em>。在</p>
<p>这意味着要重新实现<a href="https://doc.qt.io/qt-5/qlineedit.html#keyPressEvent" rel="nofollow noreferrer">QLineEdit.keyPressEvent</a>,这样您就可以捕获<a href="https://doc.qt.io/qt-5/qlineedit.html#details" rel="nofollow noreferrer">default key bindings</a>;和{a3}的快捷方式,以便您可以修改默认上下文菜单。而且,根据您要执行的操作,您可能还需要覆盖默认的拖放处理。(如果不想使用子类,可以使用<a href="https://doc.qt.io/qt-5/qobject.html#eventFilter" rel="nofollow noreferrer">event-filter</a>监视所有相关事件)。在</p>
<p><a href="https://doc.qt.io/qt-5/qclipboard.html" rel="nofollow noreferrer">QClipboard</a>类提供对系统剪贴板的访问,这将允许您在粘贴文本之前拦截文本。每个应用程序都有一个clipboard对象,可以通过<code>QApplication.clipboard()</code>或<code>qApp.clipboard()</code>访问该对象。在</p>