QClipboard(3qt)
π QClipboard π
okay so bestie, this is the manual for QClipboard from the 3qt set β it's your β¨access to the window system clipboardβ¨. yep. the whole clipboard. copy-paste central. let's get into it π«Ά
β¨ NAME β¨
QClipboard β access to the window system clipboard π
πΈ SYNOPSIS πΈ
#include <qclipboard.h>
Inherits QObject.
π Public Members
enum Mode { Clipboard, Selection }void clear ( Mode mode )void clear ()bool supportsSelection () constbool ownsSelection () constbool ownsClipboard () constvoid setSelectionMode ( bool enable ) (obsolete)bool selectionModeEnabled () const (obsolete)QString text ( Mode mode ) constQString text ( QCString & subtype, Mode mode ) constvoid setText ( const QString & text, Mode mode )QMimeSource * data ( Mode mode ) constvoid setData ( QMimeSource * src, Mode mode )QImage image ( Mode mode ) constQPixmap pixmap ( Mode mode ) constvoid setImage ( const QImage & image, Mode mode )void setPixmap ( const QPixmap & pixmap, Mode mode )QString text () constQString text ( QCString & subtype ) constvoid setText ( const QString & text )QMimeSource * data () constvoid setData ( QMimeSource * src )QImage image () constQPixmap pixmap () constvoid setImage ( const QImage & image )void setPixmap ( const QPixmap & pixmap )
π¦ Signals
void selectionChanged ()void dataChanged ()
π DESCRIPTION π
the QClipboard class gives you access to the window system clipboard. that's it. that's the whole vibe.
the clipboard is like... the simplest little mechanism ever for copying and pasting data between applications. no cap. it just works. π₯
QClipboard supports the same data types that QDragObject does, and it uses similar mechanisms too β lowkey they're cousins. if you wanna go deep on advanced clipboard usage, go read the drag-and-drop documentation, bestie. it's all there.
there's exactly ONE QClipboard object per application. one. singular. main character energy only. and you get to it with QApplication::clipboard(). π«
Example, because obviously:
QClipboard *cb = QApplication::clipboard();
// Copy text from the clipboard (paste)
QString text = cb->text(QClipboard::Clipboard);
if ( !text.isNull() )
qDebug( "The clipboard contains: " + text );
// Copy text into the clipboard
cb->setText( "This text can be pasted by other programs",
QClipboard::Clipboard );
QClipboard also comes with some convenience functions for the common data types, because it loves you:
setText()lets you exchange Unicode text π¬setPixmap()andsetImage()let you exchange QPixmaps and QImages between applications πΌοΈsetData()is the ultimate in flexibility β it lets you add anyQMimeSourceinto the clipboard. literally anything. iconic. π
and yeah there are corresponding getters for each of those, e.g. text(), image() and pixmap(). symmetry, we love to see it.
wanna wipe the clipboard? just call clear(). done. clean slate. β¨
π Platform Specific Information π
π§ X11 π§
the X11 Window System has the concept of a separate selection and clipboard. when text is selected, it's immediately available as the global mouse selection. the global mouse selection may later be copied to the clipboard. by convention, the middle mouse button is what you use to paste the global mouse selection. (middle mouse button girlies, rise π«Ά)
X11 also has the concept of ownership; if you change the selection within a window, X11 will only notify the owner and the previous owner of the change β i.e. it will not notify all applications that the selection or clipboard data changed. so if you were expecting a group chat blast to everyone... it's giving private DM only. π
lastly, the X11 clipboard is event driven, i.e. the clipboard will not function properly if the event loop is not running. similarly, it is recommended that the contents of the clipboard are stored or retrieved in direct response to user-input events, e.g. mouse button or key presses and releases. you should not store or retrieve the clipboard contents in response to timer or non-user-input events.
β οΈ no event loop = no clipboard. and don't be out here grabbing clipboard data on a timer, bestie, that's not the move. π
πͺ Windows πͺ
Microsoft Windows does not support the global mouse selection; it only supports the global clipboard, e.g. Windows only adds text to the clipboard when an explicit copy or cut is made. so no sneaky select-and-middle-click over here. π
Windows also doesn't have the concept of ownership; the clipboard is a fully global resource, so all applications are notified of changes. everyone gets the notification. no private DMs. π
see the multiclip example in the Qt Designer examples directory for an example of a multiplatform clipboard application that also demonstrates selection handling. π
see also Environment Classes and Input/Output and Networking.
π Member Type Documentation π
QClipboard::Mode
this enum type is used to control which part of the system clipboard is used by QClipboard::data(), QClipboard::setData() and related functions. it's basically the "which clipboard, bestie?" switch. π¦
QClipboard::Clipboardβ indicates that data should be stored and retrieved from the global clipboard. πQClipboard::Selectionβ indicates that data should be stored and retrieved from the global mouse selection. π±οΈ
π Note: Support for Selection is provided only on systems with a global mouse selection (e.g. X11).
see also QClipboard::supportsSelection().
π MEMBER FUNCTION DOCUMENTATION π
void QClipboard::clear ( Mode mode )
clears the clipboard contents. bye bye data. π
the mode argument is used to control which part of the system clipboard is used. if mode is QClipboard::Clipboard, this function clears the the global clipboard contents. if mode is QClipboard::Selection, this function clears the global mouse selection contents.
see also QClipboard::Mode and supportsSelection().
void QClipboard::clear ()
this is an overloaded member function, provided for convenience. it behaves essentially like the above function. π«Ά
this function uses the QClipboard::clear() function which takes a QClipboard::Mode argument. the value of the mode argument is determined by the return value of selectionModeEnabled(). if selectionModeEnabled() returns TRUE, the mode argument is QClipboard::Selection, otherwise the mode argument is QClipboard::Clipboard.
QMimeSource * QClipboard::data ( Mode mode ) const
returns a reference to a QMimeSource representation of the current clipboard data. π
the mode argument is used to control which part of the system clipboard is used. if mode is QClipboard::Clipboard, the data is retrieved from the global clipboard. if mode is QClipboard::Selection, the data is retrieved from the global mouse selection.
see also setData().
QMimeSource * QClipboard::data () const
this is an overloaded member function, provided for convenience. it behaves essentially like the above function. β¨
this function uses the QClipboard::data() function which takes a QClipboard::Mode argument. the value of the mode argument is determined by the return value of selectionModeEnabled(). if selectionModeEnabled() returns TRUE, the mode argument is QClipboard::Selection, otherwise the mode argument is QClipboard::Clipboard.
void QClipboard::dataChanged () [signal]
this signal is emitted when the clipboard data is changed. π£ literally the "hey bestie something changed" ping.
QImage QClipboard::image ( Mode mode ) 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. π
the mode argument is used to control which part of the system clipboard is used. if mode is QClipboard::Clipboard, the image is retrieved from the global clipboard. if mode is QClipboard::Selection, the image is retrieved from the global mouse selection.
see also setImage(), pixmap(), data(), and QImage::isNull().
QImage QClipboard::image () const
this is an overloaded member function, provided for convenience. it behaves essentially like the above function. π
this function uses the QClipboard::image() function which takes a QClipboard::Mode argument. the value of the mode argument is determined by the return value of selectionModeEnabled(). if selectionModeEnabled() returns TRUE, the mode argument is QClipboard::Selection, otherwise the mode argument is QClipboard::Clipboard.
bool QClipboard::ownsClipboard () const
returns TRUE if this clipboard object owns the clipboard data; otherwise returns FALSE. π the clipboard said "that's mine."
bool QClipboard::ownsSelection () const
returns TRUE if this clipboard object owns the mouse selection data; otherwise returns FALSE. π±οΈπ
same energy, different clipboard.
QPixmap QClipboard::pixmap ( Mode mode ) 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. so like... glow-down potential, fr fr. π
the mode argument is used to control which part of the system clipboard is used. if mode is QClipboard::Clipboard, the pixmap is retrieved from the global clipboard. if mode is QClipboard::Selection, the pixmap is retrieved from the global mouse selection.
see also setPixmap(), image(), data(), and QPixmap::convertFromImage().
QPixmap QClipboard::pixmap () const
this is an overloaded member function, provided for convenience. it behaves essentially like the above function. πΈ
this function uses the QClipboard::pixmap() function which takes a QClipboard::Mode argument. the value of the mode argument is determined by the return value of selectionModeEnabled(). if selectionModeEnabled() returns TRUE, the mode argument is QClipboard::Selection, otherwise the mode argument is QClipboard::Clipboard.
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
π¨ this function is obsolete. it is provided to keep old source working. we strongly advise against using it in new code.
use the QClipboard::data(), QClipboard::setData() and related functions which take a QClipboard::Mode argument instead. that's the glow-up, bestie. β¨
returns the selection mode.
see also setSelectionMode() and supportsSelection().
void QClipboard::setData ( QMimeSource * src, Mode mode )
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 mode argument is used to control which part of the system clipboard is used. if mode is QClipboard::Clipboard, the data is retrieved from the global clipboard. if mode is QClipboard::Selection, the data is retrieved from the global mouse selection.
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(), setImage() and setPixmap() functions are simpler wrappers for setting text, image and pixmap data respectively.
see also data().
void QClipboard::setData ( QMimeSource * src ) β¨
Okay bestie, this one is an overloaded member function, provided for convenience β it behaves essentially like the above function. No cap.
It uses the QClipboard::setData() function that takes a QClipboard::Mode argument. The value of the mode argument is determined by the return value of selectionModeEnabled(). If selectionModeEnabled() returns TRUE, the mode argument is QClipboard::Selection; otherwise the mode argument is QClipboard::Clipboard.
void QClipboard::setImage ( const QImage & image, Mode mode ) πΌοΈ
Copies image into the clipboard. The mode argument is used to control which part of the system clipboard is used. If mode is QClipboard::Clipboard, the image is stored in the global clipboard. If mode is QClipboard::Selection, the data is stored in the global mouse selection.
This is shorthand for:
setData( new QImageDrag(image), mode )
See also image(), setPixmap(), and setData().
void QClipboard::setImage ( const QImage & image ) πΈ
This is an overloaded member function, provided for convenience. It behaves essentially like the above function. It uses the QClipboard::setImage() function which takes a QClipboard::Mode argument. The value of the mode argument is determined by the return value of selectionModeEnabled(). If selectionModeEnabled() returns TRUE, the mode argument is QClipboard::Selection, otherwise the mode argument is QClipboard::Clipboard.
void QClipboard::setPixmap ( const QPixmap & pixmap, Mode mode ) π
Copies pixmap into the clipboard. Note that this is slower than setImage() because it needs to convert the QPixmap to a QImage first. (The way that extra conversion step eats time? Not it, but it's necessary.)
The mode argument is used to control which part of the system clipboard is used. If mode is QClipboard::Clipboard, the pixmap is stored in the global clipboard. If mode is QClipboard::Selection, the pixmap is stored in the global mouse selection.
See also pixmap(), setImage(), and setData().
void QClipboard::setPixmap ( const QPixmap & pixmap ) π
Overloaded member function, provided for convenience. It behaves essentially like the above function. This function uses the QClipboard::setPixmap() function which takes a QClipboard::Mode argument. The value of the mode argument is determined by the return value of selectionModeEnabled(). If selectionModeEnabled() returns TRUE, the mode argument is QClipboard::Selection, otherwise the mode argument is QClipboard::Clipboard.
void QClipboard::setSelectionMode ( bool enable ) π«
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
Use the QClipboard::data(), QClipboard::setData() and related functions which take a QClipboard::Mode argument instead.
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, Mode mode ) π
Copies text into the clipboard as plain text. The mode argument is used to control which part of the system clipboard is used. If mode is QClipboard::Clipboard, the text is stored in the global clipboard. If mode is QClipboard::Selection, the text is stored in the global mouse selection.
See also text() and setData().
Example: regexptester/regexptester.cpp.
void QClipboard::setText ( const QString & text ) β¨
This is an overloaded member function, provided for convenience. It behaves essentially like the above function. This function uses the QClipboard::setText() function which takes a QClipboard::Mode argument. The value of the mode argument is determined by the return value of selectionModeEnabled(). If selectionModeEnabled() returns TRUE, the mode argument is QClipboard::Selection, otherwise the mode argument is QClipboard::Clipboard.
bool QClipboard::supportsSelection () const π
Returns TRUE if the clipboard supports mouse selection; otherwise returns FALSE.
Example: regexptester/regexptester.cpp.
QString QClipboard::text ( Mode mode ) const π¬
Returns the clipboard text as plain text, or a null string if the clipboard does not contain any text. The mode argument is used to control which part of the system clipboard is used. If mode is QClipboard::Clipboard, the text is retrieved from the global clipboard. If mode is QClipboard::Selection, the text is retrieved from the global mouse selection.
See also setText(), data(), and QString::operator!().
QString QClipboard::text ( QCString & subtype, Mode mode ) const π
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
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.
The mode argument is used to control which part of the system clipboard is used. If mode is QClipboard::Clipboard, the text is retrieved from the global clipboard. If mode is QClipboard::Selection, the text is retrieved from the global mouse selection.
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. This function uses the QClipboard::text() function which takes a QClipboard::Mode argument. The value of the mode argument is determined by the return value of selectionModeEnabled(). If selectionModeEnabled() returns TRUE, the mode argument is QClipboard::Selection, otherwise the mode argument is QClipboard::Clipboard.
QString QClipboard::text ( QCString & subtype ) const π
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns the clipboard text in subtype subtype, or a null string if the clipboard does not contain any text. This function uses the QClipboard::text() function which takes a QClipboard::Mode argument. The value of the mode argument is determined by the return value of selectionModeEnabled(). If selectionModeEnabled() returns TRUE, the mode argument is QClipboard::Selection, otherwise the mode argument is QClipboard::Clipboard.
SEE ALSO π
COPYRIGHT π
Copyright 1992-2007 Trolltech ASA, 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.3.8).
Okay bestie, that's the whole vibe. This page came from Trolltech AS, dated 2 February 2007, for QClipboard(3qt). Now go forth and clip responsibly. π β¨
π¦ where this page comes from
- fedora 43: qt3-devel-docs 3.3.8b-102.fc43 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- fedora 44: qt3-devel-docs 3.3.8b-103.fc44 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms