[PyQt] cannot get clipboard text using QClipboard on Android when App in background

Zhao Lee redstone-cold at 163.com
Wed Apr 25 09:37:00 BST 2018


I am using the following code to retrieve clipboard text once clipboard data changed on Android 

from PyQt5.QtCoreimport*from PyQt5.QtGuiimport*from PyQt5.QtWidgetsimport*classEngkuDict(QLabel):
    # Permissions QFile::permissions() const

    def __init__(self, parent=None):
        super().__init__(parent)
        self.showMaximized()

        self.clipboard =QGuiApplication.clipboard()
        self.clipboard.dataChanged.connect(self.clipboardTextChanged)
        # self.clipboard.changed.connect(self.clipboardModeChanged)

    @pyqtSlot()
    def clipboardTextChanged(self):
        selectedText = self.clipboard.text()
        self.setText('clipboardTextChanged: {}'.format(selectedText))

    def clipboardModeChanged(self, mode):

        selectedText = self.clipboard.text()
        self.setText('mode: {}\n{}'.format(mode, selectedText))if __name__ =="__main__":
    import sys
    app =QApplication(sys.argv)
    # QApplication.setQuitOnLastWindowClosed(False)

    trayIcon =EngkuDict()
    trayIcon.show()
    sys.exit(app.exec_())

when the code is running in background, I copied text in another application, this application just cannot get clipboard text, so how to solve the issue ?






-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180425/0247e8ae/attachment-0001.html>


More information about the PyQt mailing list