The QClipboard class provides access to the window systems clipboard. More...
#include <qclipboard.h>
Inherits QObject.
The clipboard offers a simple mechanism to copy and paste data between applications.
QClipboard supports the same data types that drag and drop supports, and uses much of the same mechanisms.
Only a single QClipboard object may exist in an application. This is because QClipboard is a shared window system resource. Call QApplication::clipboard() to access the clipboard.
Example:
QClipboard *cb = QApplication::clipboard(); QString text; // Copy text from the clipboard (paste) text = cb->text(); if ( text ) qDebug( "The clipboard contains: %s", text ); // Copy text into the clipboard cb->setText( "This text can be pasted by other programs" );
QClipboard features some convenience functions to access common data types. The methods setText() and text() allow to exchange unicode text easily over the clipboard, while setPixmap(), setImage() and pixmap(), image() allow to exchange QPixmap and QImage between applications.
The most flexible methods are data() and setData(). They allow to put a QMimeSource() on the clipboard or retrieve it from the clipboard. This does not only allow you to put all kind of data type on the clipboard. In addition it allows you to exchange some information using different data types. For example you want to put a sound on the clipboard. Since you can not know exactly what kind of formats the other application understands you can feature multiple formats at once. This functionality is provided by QMimeSource. The application which retrieves the data from the clipboard receives a QMimeSource, too, and can select one of the offered data types.
You can clear the clipboard by calling the method clear().
Clears the clipboard contents.
Returns a reference to a QMimeSource representation of the current clipboard data.
[signal]
This signal is emitted when the clipboard data is changed.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QObject.
Returns the clipboard image, or a null image if the clipboard does not contain an image. In addition a null image may be returned if Qt does not understand the provided image format.
See also: setImage(), pixmap() and data().
Returns the clipboard pixmap, or null if the clipboard does not contain any pixmap. Note that this usually looses more information than image().
See also: setPixmap(), image() and data().
Sets the clipboard data. Ownership of the data is transferred to the clipboard - the only way to remove this data is to set something else, or to call clear(). The QDragObject subclasses are reasonable things to put on the clipboard (but do not try to drag the same object). Do not put QDragMoveEvent or QDropEvent subclasses on the clipboard, as they do not belong to the event handler which receives them.
The setText() and setPixmap() functions are shorthand ways of setting the data.
Copies image into the clipboard.
This is just a shorthand for:
setData(new QImageDrag(image))
See also: image(), setPixmap() and setData().
Copies pixmap into the clipboard. Note that this usually looses more information than setImage(), as the data may be converted to an image for transfer.
See also: pixmap(), setImage() and setData().
Copies text into the clipboard.
See also: text() and setData().
Returns the clipboard text, or a null string if the clipboard does not contain any text.
See also: setText() and data().
[virtual protected]
For internal use only.
Reimplemented from QObject.
Search the documentation, FAQ, qt-interest archive and more (uses
www.trolltech.com):
This file is part of the Qt toolkit, copyright © 1995-2000 Troll Tech, all rights reserved.
Copyright İ 2000 Troll Tech | Trademarks | Qt version 2.1.0
|