QClipboard(3qt)

πŸ“¦ version 3.3.8b, in fedora 43, fedora 44

πŸ’– 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 () const
  • bool ownsSelection () const
  • bool ownsClipboard () const
  • void setSelectionMode ( bool enable ) (obsolete)
  • bool selectionModeEnabled () const (obsolete)
  • QString text ( Mode mode ) const
  • QString text ( QCString & subtype, Mode mode ) const
  • void setText ( const QString & text, Mode mode )
  • QMimeSource * data ( Mode mode ) const
  • void setData ( QMimeSource * src, Mode mode )
  • QImage image ( Mode mode ) const
  • QPixmap pixmap ( Mode mode ) const
  • void setImage ( const QImage & image, Mode mode )
  • void setPixmap ( const QPixmap & pixmap, Mode mode )
  • QString text () const
  • QString text ( QCString & subtype ) const
  • void setText ( const QString & text )
  • QMimeSource * data () const
  • void setData ( QMimeSource * src )
  • 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 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() and setImage() let you exchange QPixmaps and QImages between applications πŸ–ΌοΈ
  • setData() is the ultimate in flexibility β€” it lets you add any QMimeSource into 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 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