QClipboard(3qt)

NAME
QClipboard - Access to the window system clipboard

SYNOPSIS
#include <qclipboard.h>

Inherits QObject.

  Public Members
void clear ()
bool supportsSelection () const
bool ownsSelection () const
bool ownsClipboard () const
void setSelectionMode ( bool enable )
bool selectionModeEnabled () const
QMimeSource * data () const
void setData ( QMimeSource * src )
QString text () const
QString text ( QCString & subtype ) const
void setText ( const QString & text )
QImage image () const
QPixmap pixmap () const
void setImage ( const QImage & image )
void setPixmap ( const QPixmap & pixmap )

  Signals
void selectionChanged ()
void dataChanged ()

DESCRIPTION
The QClipboard class provides access to the window system clipboard.

The clipboard offers a simple mechanism to copy and paste data between applications.

QClipboard supports the same data types that QDragObject does, and uses similar mechanisms. For advanced clipboard usage, you should read the drag-and-drop documentation.

There is a single QClipboard object in an application, and you can access it using QApplication::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: setText() allows the exchange of Unicode text and setPixmap() and setImage() allows the exchange of QPixmaps and QImages between applications. The setData() function is the ultimate in flexibility: it allows you to add any QMimeSource into the clipboard. (There are corresponding getters for each of these, e.g. text().)

You can clear the clipboard by calling clear().

The underlying clipboards of the X Window system and MS Windows differ. The X Window system has a concept of selection -- when text is selected, it is immediately available in the selection buffer; MS Windows only adds text to the clipboard when an explicit copy or cut is made. The X Window system also has a concept of ownership; if you change the selection within a window, X11 will only notify the owner and the previous owner of the change; in MS Windows the clipboard is a fully global resource so all applications are notified of changes. See the multiclip example in the Qt Designer examples directory for an example of a cross-platform clipboard application that also demonstrates selection handling.

See also Input/Output and Networking.

MEMBER FUNCTION DOCUMENTATION

void QClipboard::clear ()
Clears the clipboard contents.

QMimeSource * QClipboard::data () const
Returns a reference to a QMimeSource representation of the current clipboard data.

void QClipboard::dataChanged () [signal]
This signal is emitted when the clipboard data is changed.

QImage QClipboard::image () const
Returns the clipboard image, or returns a null image if the clipboard does not contain an image or if it contains an image in an unsupported image format.

See also setImage(), pixmap(), data() and QImage::isNull().

bool QClipboard::ownsClipboard () const
Returns TRUE if this clipboard object owns the clipboard data, FALSE otherwise.

bool QClipboard::ownsSelection () const
Returns TRUE if this clipboard object owns the mouse selection data, otherwise, it returns FALSE.

QPixmap QClipboard::pixmap () const
Returns the clipboard pixmap, or null if the clipboard does not contain a pixmap. Note that this can lose information. For example, if the image is 24-bit and the display is 8-bit, the result is converted to 8 bits, and if the image has an alpha channel, the result just has a mask.

See also setPixmap(), image(), data() and QPixmap::convertFromImage().

void QClipboard::selectionChanged () [signal]
This signal is emitted when the selection is changed. This only applies to windowing systems that support selections, e.g. X11. Windows doesn't support selections.

bool QClipboard::selectionModeEnabled () const
Returns the value set by setSelectionMode().

See also setSelectionMode() and supportsSelection().

void QClipboard::setData ( QMimeSource * src )
Sets the clipboard data to src. Ownership of the data is transferred to the clipboard. If you want to remove the data either call clear() or call setData() again with new data.

The QDragObject subclasses are reasonable objects to put into the clipboard (but do not try to call QDragObject::drag() on the same object). Any QDragObject placed in the clipboard should have a parent of 0. Do not put QDragMoveEvent or QDropEvent subclasses in the clipboard, as they do not belong to the event handler which receives them.

The setText() and setPixmap() functions are simpler wrappers for setting text and image data respectively.

void QClipboard::setImage ( const QImage & image )
Copies image into the clipboard.

This is shorthand for:

    setData(new QImageDrag(image))

See also image(), setPixmap() and setData().

void QClipboard::setPixmap ( const QPixmap & pixmap )
Copies pixmap into the clipboard. Note that this is slower than setImage() - it needs to convert the QPixmap to a QImage first.

See also pixmap(), setImage() and setData().

void QClipboard::setSelectionMode ( bool enable )
Sets the clipboard selection mode. If enable is TRUE, then subsequent calls to QClipboard::setData() and other functions which put data into the clipboard will put the data into the mouse selection, otherwise the data will be put into the clipboard.

See also supportsSelection() and selectionModeEnabled().

void QClipboard::setText ( const QString & text )
Copies text into the clipboard as plain text.

See also text() and setData().

bool QClipboard::supportsSelection () const
Returns TRUE if the clipboard supports mouse selection, otherwise, it returns FALSE.

QString QClipboard::text ( QCString & subtype ) const
Returns the clipboard text in subtype subtype, or a null string if the clipboard does not contain any text. If subtype is null, any subtype is acceptable, and subtype is set to the chosen subtype.

Common values for subtype are "plain" and "html".

See also setText(), data() and QString::operator!().

QString QClipboard::text () const
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the clipboard text as plain text, or a null string if the clipboard does not contain any text.

See also setText(), data() and QString::operator!().

SEE ALSO
http://doc.trolltech.com/qclipboard.html http://www.trolltech.com/faq/tech.html

COPYRIGHT
Copyright 1992-2001 Trolltech AS, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.

AUTHOR
Generated automatically from the source code.

BUGS
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you.

The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech.

If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qclipboard.3qt) and the Qt version (3.0.3).