Accessing the clipboard (Qt)

Last edited on

Overview

Sometimes the system clipboard contents must be tested.

Testing Text Contents

The following example demonstrates this for text data using the getClipboardText function (also note setClipboardText ).

Python

def main():
    startApplication("myaut")

    test.compare("Expected text.", getClipboardText())
test.py

JavaScript

function main() {
    startApplication("myaut");

    test.compare("Expected text.", getClipboardText());
}
test.js

Testing Image Contents

Python

clipboard_image_viewer = None

def main():
    startApplication("...")

    #...

    show_clipboard_image()

    # This screenshot VP has been created at a
    # breakpoint after
    # executing show_clipboard_image():
    test.vp("my_screenshot_vp")

    hide_clipboard_image()

def get_clipboard_image_viewer():
    global clipboard_image_viewer
    if clipboard_image_viewer is None:
        clipboard_image_viewer = QLabel()
        clipboard_image_viewer.setObjectName("clipboard_image_viewer")
    return clipboard_image_viewer

def show_clipboard_image():
    clipboard_image_viewer = get_clipboard_image_viewer()
    cb = QApplication.clipboard()
    pm = cb.pixmap()
    clipboard_image_viewer.setPixmap(pm)
    clipboard_image_viewer.show()

def hide_clipboard_image():
    get_clipboard_image_viewer().setVisible(False)
test.py