<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <!-- /home/reggie/tmp/qt-3.1-reggie-23625/qt-x11-free-3.1.1/src/kernel/qclipboard.cpp:47 --> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>QClipboard Class</title> <style type="text/css"><!-- h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; } a:link { color: #004faf; text-decoration: none } a:visited { color: #672967; text-decoration: none } body { background: #ffffff; color: black; } --></style> </head> <body> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr bgcolor="#E5E5E5"> <td valign=center> <a href="index.html"> <font color="#004faf">Home</font></a> | <a href="classes.html"> <font color="#004faf">All Classes</font></a> | <a href="mainclasses.html"> <font color="#004faf">Main Classes</font></a> | <a href="annotated.html"> <font color="#004faf">Annotated</font></a> | <a href="groups.html"> <font color="#004faf">Grouped Classes</font></a> | <a href="functions.html"> <font color="#004faf">Functions</font></a> </td> <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QClipboard Class Reference</h1> <p>The QClipboard class provides access to the window system clipboard. <a href="#details">More...</a> <p><tt>#include <<a href="qclipboard-h.html">qclipboard.h</a>></tt> <p>Inherits <a href="qobject.html">QObject</a>. <p><a href="qclipboard-members.html">List of all member functions.</a> <h2>Public Members</h2> <ul> <li><div class=fn>enum <a href="#Mode-enum"><b>Mode</b></a> { Clipboard, Selection }</div></li> <li><div class=fn>void <a href="#clear"><b>clear</b></a> ( Mode mode )</div></li> <li><div class=fn>void clear () <em>(obsolete)</em></div></li> <li><div class=fn>bool <a href="#supportsSelection"><b>supportsSelection</b></a> () const</div></li> <li><div class=fn>bool <a href="#ownsSelection"><b>ownsSelection</b></a> () const</div></li> <li><div class=fn>bool <a href="#ownsClipboard"><b>ownsClipboard</b></a> () const</div></li> <li><div class=fn>void setSelectionMode ( bool enable ) <em>(obsolete)</em></div></li> <li><div class=fn>bool selectionModeEnabled () const <em>(obsolete)</em></div></li> <li><div class=fn>QString <a href="#text"><b>text</b></a> ( Mode mode ) const</div></li> <li><div class=fn>QString <a href="#text-2"><b>text</b></a> ( QCString & subtype, Mode mode ) const</div></li> <li><div class=fn>void <a href="#setText"><b>setText</b></a> ( const QString & text, Mode mode )</div></li> <li><div class=fn>QMimeSource * <a href="#data"><b>data</b></a> ( Mode mode ) const</div></li> <li><div class=fn>void <a href="#setData"><b>setData</b></a> ( QMimeSource * src, Mode mode )</div></li> <li><div class=fn>QImage <a href="#image"><b>image</b></a> ( Mode mode ) const</div></li> <li><div class=fn>QPixmap <a href="#pixmap"><b>pixmap</b></a> ( Mode mode ) const</div></li> <li><div class=fn>void <a href="#setImage"><b>setImage</b></a> ( const QImage & image, Mode mode )</div></li> <li><div class=fn>void <a href="#setPixmap"><b>setPixmap</b></a> ( const QPixmap & pixmap, Mode mode )</div></li> <li><div class=fn>QString text () const <em>(obsolete)</em></div></li> <li><div class=fn>QString text ( QCString & subtype ) const <em>(obsolete)</em></div></li> <li><div class=fn>void setText ( const QString & text ) <em>(obsolete)</em></div></li> <li><div class=fn>QMimeSource * data () const <em>(obsolete)</em></div></li> <li><div class=fn>void setData ( QMimeSource * src ) <em>(obsolete)</em></div></li> <li><div class=fn>QImage image () const <em>(obsolete)</em></div></li> <li><div class=fn>QPixmap pixmap () const <em>(obsolete)</em></div></li> <li><div class=fn>void setImage ( const QImage & image ) <em>(obsolete)</em></div></li> <li><div class=fn>void setPixmap ( const QPixmap & pixmap ) <em>(obsolete)</em></div></li> </ul> <h2>Signals</h2> <ul> <li><div class=fn>void <a href="#selectionChanged"><b>selectionChanged</b></a> ()</div></li> <li><div class=fn>void <a href="#dataChanged"><b>dataChanged</b></a> ()</div></li> </ul> <hr><a name="details"></a><h2>Detailed Description</h2> The QClipboard class provides access to the window system clipboard. <p> <p> The clipboard offers a simple mechanism to copy and paste data between applications. <p> QClipboard supports the same data types that <a href="qdragobject.html">QDragObject</a> does, and uses similar mechanisms. For advanced clipboard usage read <a href="dnd.html">the drag-and-drop documentation</a>. <p> There is a single QClipboard object in an application, and you can access it using <a href="qapplication.html#clipboard">QApplication::clipboard</a>(). <p> Example: <pre> QClipboard *cb = QApplication::<a href="qapplication.html#clipboard">clipboard</a>(); <a href="qstring.html">QString</a> text; // Copy text from the clipboard (paste) text = cb-><a href="#text">text</a>(); if ( text ) <a href="qapplication.html#qDebug">qDebug</a>( "The clipboard contains: %s", text ); // Copy text into the clipboard cb-><a href="#setText">setText</a>( "This text can be pasted by other programs" ); </pre> <p> QClipboard features some convenience functions to access common data types: <a href="#setText">setText</a>() allows the exchange of Unicode text and <a href="#setPixmap">setPixmap</a>() and <a href="#setImage">setImage</a>() allows the exchange of QPixmaps and QImages between applications. The <a href="#setData">setData</a>() function is the ultimate in flexibility: it allows you to add any <a href="qmimesource.html">QMimeSource</a> into the clipboard. There are corresponding getters for each of these, e.g. <a href="#text">text</a>(), <a href="#image">image</a>() and <a href="#pixmap">pixmap</a>(). <p> You can clear the clipboard by calling <a href="#clear">clear</a>(). <p> 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 as the global mouse selection; 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 <em>Qt Designer</em> examples directory for an example of a multiplatform clipboard application that also demonstrates selection handling. <p>See also <a href="environment.html">Environment Classes</a> and <a href="io.html">Input/Output and Networking</a>. <hr><h2>Member Type Documentation</h2> <h3 class=fn><a name="Mode-enum"></a>QClipboard::Mode</h3> <!-- index clipboard mode --> <p> This enum type is used to control which part of the system clipboard is used by <a href="#data">QClipboard::data</a>(), <a href="#setData">QClipboard::setData</a>() and related functions. <ul> <li><tt>QClipboard::Clipboard</tt> - indicates that data should be stored and retreived from the global clipboard. <li><tt>QClipboard::Selection</tt> - indicates that data should be stored and retreived from the global mouse selection. </ul><p> <em>Note</em>: Support for <a href="#Mode-enum">Selection</a> is provided only on systems with a global mouse selection (e.g. X11). <p> <p>See also <a href="#supportsSelection">QClipboard::supportsSelection</a>(). <hr><h2>Member Function Documentation</h2> <h3 class=fn>void <a name="clear"></a>QClipboard::clear ( <a href="qclipboard.html#Mode-enum">Mode</a> mode ) </h3> Clear the clipboard contents. <p> The <em>mode</em> argument is used to control which part of the system clipboard is used. If <em>mode</em> is QClipboard::Clipboard, this function clears the the global clipboard contents. If <em>mode</em> is QClipboard::Selection, this function clears the global mouse selection contents. <p> <p>See also <a href="#Mode-enum">QClipboard::Mode</a> and <a href="#supportsSelection">supportsSelection</a>(). <h3 class=fn>void <a name="clear-2"></a>QClipboard::clear () </h3> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code. <p> This function uses the <a href="#clear">QClipboard::clear</a>() function which takes a QClipboard::Mode argument. The value of the mode argument is determined by the return value of <a href="#selectionModeEnabled">selectionModeEnabled</a>(). If selectionModeEnabled() returns TRUE, the mode argument is QClipboard::Selection, otherwise the mode argument is QClipboard::Clipboard. <h3 class=fn><a href="qmimesource.html">QMimeSource</a> * <a name="data"></a>QClipboard::data ( <a href="qclipboard.html#Mode-enum">Mode</a> mode ) const </h3> Returns a reference to a <a href="qmimesource.html">QMimeSource</a> representation of the current clipboard data. <p> The <em>mode</em> argument is used to control which part of the system clipboard is used. If <em>mode</em> is QClipboard::Clipboard, the data is retreived from the global clipboard. If <em>mode</em> is QClipboard::Selection, the data is retreived from the global mouse selection. <p> <p>See also <a href="#setData">setData</a>(). <h3 class=fn><a href="qmimesource.html">QMimeSource</a> * <a name="data-2"></a>QClipboard::data () const </h3> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code. <p> This function uses the <a href="#data">QClipboard::data</a>() function which takes a QClipboard::Mode argument. The value of the mode argument is determined by the return value of <a href="#selectionModeEnabled">selectionModeEnabled</a>(). If selectionModeEnabled() returns TRUE, the mode argument is QClipboard::Selection, otherwise the mode argument is QClipboard::Clipboard. <h3 class=fn>void <a name="dataChanged"></a>QClipboard::dataChanged ()<tt> [signal]</tt> </h3> <p> This signal is emitted when the clipboard data is changed. <h3 class=fn><a href="qimage.html">QImage</a> <a name="image"></a>QClipboard::image ( <a href="qclipboard.html#Mode-enum">Mode</a> mode ) const </h3> 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. <p> The <em>mode</em> argument is used to control which part of the system clipboard is used. If <em>mode</em> is QClipboard::Clipboard, the image is retreived from the global clipboard. If <em>mode</em> is QClipboard::Selection, the image is retreived from the global mouse selection. <p> <p>See also <a href="#setImage">setImage</a>(), <a href="#pixmap">pixmap</a>(), <a href="#data">data</a>(), and <a href="qimage.html#isNull">QImage::isNull</a>(). <h3 class=fn><a href="qimage.html">QImage</a> <a name="image-2"></a>QClipboard::image () const </h3> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code. <p> This function uses the <a href="#image">QClipboard::image</a>() function which takes a QClipboard::Mode argument. The value of the mode argument is determined by the return value of <a href="#selectionModeEnabled">selectionModeEnabled</a>(). If selectionModeEnabled() returns TRUE, the mode argument is QClipboard::Selection, otherwise the mode argument is QClipboard::Clipboard. <h3 class=fn>bool <a name="ownsClipboard"></a>QClipboard::ownsClipboard () const </h3> Returns TRUE if this clipboard object owns the clipboard data; otherwise returns FALSE. <h3 class=fn>bool <a name="ownsSelection"></a>QClipboard::ownsSelection () const </h3> Returns TRUE if this clipboard object owns the mouse selection data; otherwise returns FALSE. <h3 class=fn><a href="qpixmap.html">QPixmap</a> <a name="pixmap"></a>QClipboard::pixmap ( <a href="qclipboard.html#Mode-enum">Mode</a> mode ) const </h3> 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. <p> The <em>mode</em> argument is used to control which part of the system clipboard is used. If <em>mode</em> is QClipboard::Clipboard, the pixmap is retreived from the global clipboard. If <em>mode</em> is QClipboard::Selection, the pixmap is retreived from the global mouse selection. <p> <p>See also <a href="#setPixmap">setPixmap</a>(), <a href="#image">image</a>(), <a href="#data">data</a>(), and <a href="qpixmap.html#convertFromImage">QPixmap::convertFromImage</a>(). <h3 class=fn><a href="qpixmap.html">QPixmap</a> <a name="pixmap-2"></a>QClipboard::pixmap () const </h3> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code. <p> This function uses the <a href="#pixmap">QClipboard::pixmap</a>() function which takes a QClipboard::Mode argument. The value of the mode argument is determined by the return value of <a href="#selectionModeEnabled">selectionModeEnabled</a>(). If selectionModeEnabled() returns TRUE, the mode argument is QClipboard::Selection, otherwise the mode argument is QClipboard::Clipboard. <h3 class=fn>void <a name="selectionChanged"></a>QClipboard::selectionChanged ()<tt> [signal]</tt> </h3> <p> 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. <h3 class=fn>bool <a name="selectionModeEnabled"></a>QClipboard::selectionModeEnabled () const </h3> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code. <p> Use the <a href="#data">QClipboard::data</a>(), <a href="#setData">QClipboard::setData</a>() and related functions which take a QClipboard::Mode argument. <p> Returns the selection mode. <p> <p>See also <a href="#setSelectionMode">setSelectionMode</a>() and <a href="#supportsSelection">supportsSelection</a>(). <h3 class=fn>void <a name="setData"></a>QClipboard::setData ( <a href="qmimesource.html">QMimeSource</a> * src, <a href="qclipboard.html#Mode-enum">Mode</a> mode ) </h3> Sets the clipboard data to <em>src</em>. Ownership of the data is transferred to the clipboard. If you want to remove the data either call <a href="#clear">clear</a>() or call <a href="#setData">setData</a>() again with new data. <p> The <em>mode</em> argument is used to control which part of the system clipboard is used. If <em>mode</em> is QClipboard::Clipboard, the data is retreived from the global clipboard. If <em>mode</em> is QClipboard::Selection, the data is retreived from the global mouse selection. <p> The <a href="qdragobject.html">QDragObject</a> subclasses are reasonable objects to put into the clipboard (but do not try to call <a href="qdragobject.html#drag">QDragObject::drag</a>() on the same object). Any QDragObject placed in the clipboard should have a parent of 0. Do not put <a href="qdragmoveevent.html">QDragMoveEvent</a> or <a href="qdropevent.html">QDropEvent</a> subclasses in the clipboard, as they do not belong to the event handler which receives them. <p> The <a href="#setText">setText</a>(), <a href="#setImage">setImage</a>() and <a href="#setPixmap">setPixmap</a>() functions are simpler wrappers for setting text, image and pixmap data respectively. <p> <p>See also <a href="#data">data</a>(). <h3 class=fn>void <a name="setData-2"></a>QClipboard::setData ( <a href="qmimesource.html">QMimeSource</a> * src ) </h3> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code. <p> This function uses the <a href="#setData">QClipboard::setData</a>() function which takes a QClipboard::Mode argument. The value of the mode argument is determined by the return value of <a href="#selectionModeEnabled">selectionModeEnabled</a>(). If selectionModeEnabled() returns TRUE, the mode argument is QClipboard::Selection, otherwise the mode argument is QClipboard::Clipboard. <h3 class=fn>void <a name="setImage"></a>QClipboard::setImage ( const <a href="qimage.html">QImage</a> & image, <a href="qclipboard.html#Mode-enum">Mode</a> mode ) </h3> Copies <em>image</em> into the clipboard. <p> The <em>mode</em> argument is used to control which part of the system clipboard is used. If <em>mode</em> is QClipboard::Clipboard, the image is stored in the global clipboard. If <em>mode</em> is QClipboard::Selection, the data is stored in the global mouse selection. <p> This is shorthand for: <pre> <a href="#setData">setData</a>( new <a href="qimagedrag.html">QImageDrag</a>(image), mode ) </pre> <p> <p>See also <a href="#image">image</a>(), <a href="#setPixmap">setPixmap</a>(), and <a href="#setData">setData</a>(). <h3 class=fn>void <a name="setImage-2"></a>QClipboard::setImage ( const <a href="qimage.html">QImage</a> & image ) </h3> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code. <p> This function uses the <a href="#setImage">QClipboard::setImage</a>() function which takes a QClipboard::Mode argument. The value of the mode argument is determined by the return value of <a href="#selectionModeEnabled">selectionModeEnabled</a>(). If selectionModeEnabled() returns TRUE, the mode argument is QClipboard::Selection, otherwise the mode argument is QClipboard::Clipboard. <h3 class=fn>void <a name="setPixmap"></a>QClipboard::setPixmap ( const <a href="qpixmap.html">QPixmap</a> & pixmap, <a href="qclipboard.html#Mode-enum">Mode</a> mode ) </h3> Copies <em>pixmap</em> into the clipboard. Note that this is slower than <a href="#setImage">setImage</a>() because it needs to convert the <a href="qpixmap.html">QPixmap</a> to a <a href="qimage.html">QImage</a> first. <p> The <em>mode</em> argument is used to control which part of the system clipboard is used. If <em>mode</em> is QClipboard::Clipboard, the pixmap is stored in the global clipboard. If <em>mode</em> is QClipboard::Selection, the pixmap is stored in the global mouse selection. <p> <p>See also <a href="#pixmap">pixmap</a>(), <a href="#setImage">setImage</a>(), and <a href="#setData">setData</a>(). <h3 class=fn>void <a name="setPixmap-2"></a>QClipboard::setPixmap ( const <a href="qpixmap.html">QPixmap</a> & pixmap ) </h3> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code. <p> This function uses the <a href="#setPixmap">QClipboard::setPixmap</a>() function which takes a QClipboard::Mode argument. The value of the mode argument is determined by the return value of <a href="#selectionModeEnabled">selectionModeEnabled</a>(). If selectionModeEnabled() returns TRUE, the mode argument is QClipboard::Selection, otherwise the mode argument is QClipboard::Clipboard. <h3 class=fn>void <a name="setSelectionMode"></a>QClipboard::setSelectionMode ( bool enable ) </h3> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code. <p> Use the <a href="#data">QClipboard::data</a>(), <a href="#setData">QClipboard::setData</a>() and related functions which take a QClipboard::Mode argument. <p> Sets the clipboard selection mode. If <em>enable</em> 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. <p> <p>See also <a href="#supportsSelection">supportsSelection</a>() and <a href="#selectionModeEnabled">selectionModeEnabled</a>(). <h3 class=fn>void <a name="setText"></a>QClipboard::setText ( const <a href="qstring.html">QString</a> & text, <a href="qclipboard.html#Mode-enum">Mode</a> mode ) </h3> Copies <em>text</em> into the clipboard as plain text. <p> The <em>mode</em> argument is used to control which part of the system clipboard is used. If <em>mode</em> is QClipboard::Clipboard, the text is stored in the global clipboard. If <em>mode</em> is QClipboard::Selection, the text is stored in the global mouse selection. <p> <p>See also <a href="#text">text</a>() and <a href="#setData">setData</a>(). <h3 class=fn>void <a name="setText-2"></a>QClipboard::setText ( const <a href="qstring.html">QString</a> & text ) </h3> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code. <p> This function uses the <a href="#setText">QClipboard::setText</a>() function which takes a QClipboard::Mode argument. The value of the mode argument is determined by the return value of <a href="#selectionModeEnabled">selectionModeEnabled</a>(). If selectionModeEnabled() returns TRUE, the mode argument is QClipboard::Selection, otherwise the mode argument is QClipboard::Clipboard. <h3 class=fn>bool <a name="supportsSelection"></a>QClipboard::supportsSelection () const </h3> Returns TRUE if the clipboard supports mouse selection; otherwise returns FALSE. <h3 class=fn><a href="qstring.html">QString</a> <a name="text"></a>QClipboard::text ( <a href="qclipboard.html#Mode-enum">Mode</a> mode ) const </h3> Returns the clipboard text as plain text, or a null string if the clipboard does not contain any text. <p> The <em>mode</em> argument is used to control which part of the system clipboard is used. If <em>mode</em> is QClipboard::Clipboard, the text is retreived from the global clipboard. If <em>mode</em> is QClipboard::Selection, the text is retreived from the global mouse selection. <p> <p>See also <a href="#setText">setText</a>(), <a href="#data">data</a>(), and <a href="qstring.html#operator!">QString::operator!</a>(). <h3 class=fn><a href="qstring.html">QString</a> <a name="text-2"></a>QClipboard::text ( <a href="qcstring.html">QCString</a> & subtype, <a href="qclipboard.html#Mode-enum">Mode</a> mode ) const </h3> This is an overloaded member function, provided for convenience. It behaves essentially like the above function. <p> Returns the clipboard text in subtype <em>subtype</em>, or a null string if the clipboard does not contain any text. If <em>subtype</em> is null, any subtype is acceptable, and <em>subtype</em> is set to the chosen subtype. <p> The <em>mode</em> argument is used to control which part of the system clipboard is used. If <em>mode</em> is QClipboard::Clipboard, the text is retreived from the global clipboard. If <em>mode</em> is QClipboard::Selection, the text is retreived from the global mouse selection. <p> Common values for <em>subtype</em> are "plain" and "html". <p> <p>See also <a href="#setText">setText</a>(), <a href="#data">data</a>(), and <a href="qstring.html#operator!">QString::operator!</a>(). <h3 class=fn><a href="qstring.html">QString</a> <a name="text-3"></a>QClipboard::text () const </h3> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code. <p> This function uses the <a href="#text">QClipboard::text</a>() function which takes a QClipboard::Mode argument. The value of the mode argument is determined by the return value of <a href="#selectionModeEnabled">selectionModeEnabled</a>(). If selectionModeEnabled() returns TRUE, the mode argument is QClipboard::Selection, otherwise the mode argument is QClipboard::Clipboard. <h3 class=fn><a href="qstring.html">QString</a> <a name="text-4"></a>QClipboard::text ( <a href="qcstring.html">QCString</a> & subtype ) const </h3> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code. <p> This function uses the <a href="#text">QClipboard::text</a>() function which takes a QClipboard::Mode argument. The value of the mode argument is determined by the return value of <a href="#selectionModeEnabled">selectionModeEnabled</a>(). If selectionModeEnabled() returns TRUE, the mode argument is QClipboard::Selection, otherwise the mode argument is QClipboard::Clipboard. <!-- eof --> <hr><p> This file is part of the <a href="index.html">Qt toolkit</a>. Copyright © 1995-2002 <a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center> <table width=100% cellspacing=0 border=0><tr> <td>Copyright © 2002 <a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a> <td align=right><div align=right>Qt version 3.1.1</div> </table></div></address></body> </html>