Qt 4.8
Public Types | Signals | Public Functions | Protected Functions | Private Slots | Private Functions | Friends | List of all members
QClipboard Class Reference

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

#include <qclipboard.h>

Inheritance diagram for QClipboard:
QObject

Public Types

enum  Mode { Clipboard, Selection, FindBuffer, LastMode = FindBuffer }
 This enum type is used to control which part of the system clipboard is used by QClipboard::mimeData(), QClipboard::setMimeData() and related functions. More...
 

Signals

void changed (QClipboard::Mode mode)
 This signal is emitted when the data for the given clipboard mode is changed. More...
 
void dataChanged ()
 This signal is emitted when the clipboard data is changed. More...
 
void findBufferChanged ()
 This signal is emitted when the find buffer is changed. More...
 
void selectionChanged ()
 This signal is emitted when the selection is changed. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

void clear (Mode mode=Clipboard)
 Clear the clipboard contents. More...
 
QImage image (Mode mode=Clipboard) 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. More...
 
const QMimeDatamimeData (Mode mode=Clipboard) const
 Returns a reference to a QMimeData representation of the current clipboard data. More...
 
bool ownsClipboard () const
 Returns true if this clipboard object owns the clipboard data; otherwise returns false. More...
 
bool ownsFindBuffer () const
 Returns true if this clipboard object owns the find buffer data; otherwise returns false. More...
 
bool ownsSelection () const
 Returns true if this clipboard object owns the mouse selection data; otherwise returns false. More...
 
QPixmap pixmap (Mode mode=Clipboard) const
 Returns the clipboard pixmap, or null if the clipboard does not contain a pixmap. More...
 
void setImage (const QImage &, Mode mode=Clipboard)
 Copies the image into the clipboard. More...
 
void setMimeData (QMimeData *data, Mode mode=Clipboard)
 Sets the clipboard data to src. More...
 
void setPixmap (const QPixmap &, Mode mode=Clipboard)
 Copies pixmap into the clipboard. More...
 
void setText (const QString &, Mode mode=Clipboard)
 Copies text into the clipboard as plain text. More...
 
bool supportsFindBuffer () const
 Returns true if the clipboard supports a separate search buffer; otherwise returns false. More...
 
bool supportsSelection () const
 Returns true if the clipboard supports mouse selection; otherwise returns false. More...
 
QString text (Mode mode=Clipboard) const
 Returns the clipboard text as plain text, or an empty string if the clipboard does not contain any text. More...
 
QString text (QString &subtype, Mode mode=Clipboard) const
 Returns the clipboard text in subtype subtype, or an empty string if the clipboard does not contain any text. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

void connectNotify (const char *)
 Internal optimization for Windows. More...
 
bool event (QEvent *)
 Reimplemented Function More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Private Slots

void ownerDestroyed ()
 Internal cleanup for Windows. More...
 

Private Functions

void emitChanged (Mode mode)
 Emits the appropriate changed signal for mode. More...
 
bool ownsMode (Mode mode) const
 Returns true if the clipboard supports the clipboard data speacified by mode; otherwise returns false. More...
 
 QClipboard (QObject *parent)
 
bool supportsMode (Mode mode) const
 Returns true if the clipboard supports the clipboard mode speacified by mode; otherwise returns false. More...
 
 ~QClipboard ()
 

Friends

class QApplication
 
class QApplicationPrivate
 
class QBaseApplication
 
class QDragManager
 
class QMimeSource
 
class QPlatformClipboard
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed 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 QDrag does, and uses similar mechanisms. For advanced clipboard usage read Drag and Drop.

There is a single QClipboard object in an application, accessible as QApplication::clipboard().

Example:

QString originalText = clipboard->text();
...
clipboard->setText(newText);

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 setMimeData() function is the ultimate in flexibility: it allows you to add any QMimeData into the clipboard. There are corresponding getters for each of these, e.g. text(), image() and pixmap(). You can clear the clipboard by calling clear().

A typical example of the use of these functions follows:

void DropArea::paste()
{
const QClipboard *clipboard = QApplication::clipboard();
const QMimeData *mimeData = clipboard->mimeData();
if (mimeData->hasImage()) {
setPixmap(qvariant_cast<QPixmap>(mimeData->imageData()));
} else if (mimeData->hasHtml()) {
setText(mimeData->html());
setTextFormat(Qt::RichText);
} else if (mimeData->hasText()) {
setText(mimeData->text());
setTextFormat(Qt::PlainText);
} else {
setText(tr("Cannot display data"));
}

Notes for X11 Users

Notes for Mac OS X Users

Mac OS X supports a separate find buffer that holds the current search string in Find operations. This find clipboard can be accessed by specifying the FindBuffer mode.

Notes for Windows and Mac OS X Users

See also
QApplication

Definition at line 62 of file qclipboard.h.

Enumerations

◆ Mode

This enum type is used to control which part of the system clipboard is used by QClipboard::mimeData(), QClipboard::setMimeData() and related functions.

clipboard mode

  • Clipboard indicates that data should be stored and retrieved from the global clipboard.
  • Selection indicates that data should be stored and retrieved from the global mouse selection. Support for Selection is provided only on systems with a global mouse selection (e.g. X11).
  • FindBuffer indicates that data should be stored and retrieved from the Find buffer. This mode is used for holding search strings on Mac OS X.
  • LastMode
See also
QClipboard::supportsSelection()
Enumerator
Clipboard 
Selection 
FindBuffer 
LastMode 

Definition at line 71 of file qclipboard.h.

Constructors and Destructors

◆ QClipboard()

QClipboard::QClipboard ( QObject parent)
private

Definition at line 430 of file qclipboard_x11.cpp.

431  : QObject(*new QClipboardPrivate, parent)
432 {
433  // create desktop widget since we need it to get PropertyNotify or
434  // XFixesSelectionNotify events when someone changes the
435  // clipboard.
436  (void)QApplication::desktop();
437 
438 #ifndef QT_NO_XFIXES
439  if (X11->use_xfixes && X11->ptrXFixesSelectSelectionInput) {
440  const unsigned long eventMask =
441  XFixesSetSelectionOwnerNotifyMask | XFixesSelectionWindowDestroyNotifyMask | XFixesSelectionClientCloseNotifyMask;
442  for (int i = 0; i < X11->screenCount; ++i) {
443  X11->ptrXFixesSelectSelectionInput(X11->display, QX11Info::appRootWindow(i),
444  XA_PRIMARY, eventMask);
445  X11->ptrXFixesSelectSelectionInput(X11->display, QX11Info::appRootWindow(i),
446  ATOM(CLIPBOARD), eventMask);
447  }
448  }
449 #endif // QT_NO_XFIXES
450 
451  if (X11->time == CurrentTime) {
452  // send a dummy event to myself to get the timestamp from X11.
454  data.timestamp = CurrentTime;
455  XEvent ev;
456  XCheckIfEvent(X11->display, &ev, &qt_init_timestamp_scanner, (XPointer)&data);
457  if (data.timestamp == CurrentTime) {
458  setupOwner();
459  // We need this value just for completeness, we don't use it.
460  long dummy = 0;
461  Window ownerId = owner->internalWinId();
462  XChangeProperty(X11->display, ownerId,
463  ATOM(CLIP_TEMPORARY), XA_INTEGER, 32,
464  PropModeReplace, (uchar*)&dummy, 1);
465  XWindowEvent(X11->display, ownerId, PropertyChangeMask, &ev);
466  data.timestamp = ev.xproperty.time;
467  XDeleteProperty(X11->display, ownerId, ATOM(CLIP_TEMPORARY));
468  }
469  X11->time = data.timestamp;
470  }
471 }
static void setupOwner()
static Qt::HANDLE appRootWindow(int screen=-1)
Returns a handle for the applications root window on the given screen.
static QWidget * owner
#define X11
Definition: qt_x11_p.h:724
union _XEvent XEvent
Definition: qwindowdefs.h:116
#define ATOM(x)
Definition: qt_x11_p.h:723
unsigned char uchar
Definition: qglobal.h:994
static const char * data(const QByteArray &arr)
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
char * XPointer
Definition: qt_x11_p.h:180
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
WId internalWinId() const
Returns the window system identifier of the widget, or 0 if the widget is not created yet...
Definition: qwidget.h:244
static Bool qt_init_timestamp_scanner(Display *, XEvent *event, XPointer arg)

◆ ~QClipboard()

QClipboard::~QClipboard ( )
private

Definition at line 254 of file qclipboard_win.cpp.

255 {
257 }
static void cleanupClipboardData()

Functions

◆ changed

void QClipboard::changed ( QClipboard::Mode  mode)
signal

This signal is emitted when the data for the given clipboard mode is changed.

Since
4.2
See also
dataChanged(), selectionChanged(), findBufferChanged()

◆ clear()

void QClipboard::clear ( Mode  mode = Clipboard)

Clear the clipboard contents.

The mode argument is used to control which part of the system clipboard is used. If mode is QClipboard::Clipboard, this function clears the global clipboard contents. If mode is QClipboard::Selection, this function clears the global mouse selection contents. If mode is QClipboard::FindBuffer, this function clears the search string buffer.

See also
QClipboard::Mode, supportsSelection()

Definition at line 99 of file qclipboard_mac.cpp.

Referenced by clipboardData(), and ~QClipboard().

100 {
101  if (!supportsMode(mode))
102  return;
103  qt_mac_updateScrap(mode);
104  qt_mac_pasteboard(mode)->clear();
105  setMimeData(0, mode);
106 }
bool supportsMode(Mode mode) const
Returns true if the clipboard supports the clipboard mode speacified by mode; otherwise returns false...
void setMimeData(QMimeData *data, Mode mode=Clipboard)
Sets the clipboard data to src.
static QMacPasteboard * qt_mac_pasteboard(QClipboard::Mode mode)
static bool qt_mac_updateScrap(QClipboard::Mode mode)

◆ connectNotify()

void QClipboard::connectNotify ( const char *  signal)
protectedvirtual

Internal optimization for Windows.

Warning
This function is not part of the public interface.

Reimplemented from QObject.

Definition at line 113 of file qclipboard_mac.cpp.

Referenced by clipboardData(), and isProcessBeingDebugged().

114 {
115  Q_UNUSED(signal);
116 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ dataChanged

void QClipboard::dataChanged ( )
signal

This signal is emitted when the clipboard data is changed.

On Mac OS X and with Qt version 4.3 or higher, clipboard changes made by other applications will only be detected when the application is activated.

See also
findBufferChanged(), selectionChanged(), changed()

◆ emitChanged()

void QClipboard::emitChanged ( Mode  mode)
private

Emits the appropriate changed signal for mode.

Warning
This function is not part of the public interface.

Definition at line 640 of file qclipboard.cpp.

Referenced by QPlatformClipboard::emitChanged(), event(), and setMimeData().

641 {
642  switch (mode) {
643  case Clipboard:
644  emit dataChanged();
645  break;
646  case Selection:
648  break;
649  case FindBuffer:
651  break;
652  default:
653  break;
654  }
655  emit changed(mode);
656 }
void changed(QClipboard::Mode mode)
This signal is emitted when the data for the given clipboard mode is changed.
#define emit
Definition: qobjectdefs.h:76
void dataChanged()
This signal is emitted when the clipboard data is changed.
void findBufferChanged()
This signal is emitted when the find buffer is changed.
void selectionChanged()
This signal is emitted when the selection is changed.

◆ event()

bool QClipboard::event ( QEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QObject.

Definition at line 118 of file qclipboard_mac.cpp.

Referenced by clipboardData(), QX11Data::clipboardReadIncrementalProperty(), isProcessBeingDebugged(), and qt_x11_clipboard_event_filter().

119 {
120  if(e->type() != QEvent::Clipboard)
121  return QObject::event(e);
122 
125  }
126 
129  }
130 
131  return QObject::event(e);
132 }
void emitChanged(Mode mode)
Emits the appropriate changed signal for mode.
Definition: qclipboard.cpp:640
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
static bool qt_mac_updateScrap(QClipboard::Mode mode)
Type type() const
Returns the event type.
Definition: qcoreevent.h:303

◆ findBufferChanged

void QClipboard::findBufferChanged ( )
signal

This signal is emitted when the find buffer is changed.

Since
4.2

This only applies to Mac OS X.

With Qt version 4.3 or higher, clipboard changes made by other applications will only be detected when the application is activated.

See also
dataChanged(), selectionChanged(), changed()

◆ image()

QImage QClipboard::image ( Mode  mode = Clipboard) 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() mimeData(), QImage::isNull()

Definition at line 395 of file qclipboard.cpp.

396 {
397  const QMimeData *data = mimeData(mode);
398  if (!data)
399  return QImage();
400  return qvariant_cast<QImage>(data->imageData());
401 }
const QMimeData * mimeData(Mode mode=Clipboard) const
Returns a reference to a QMimeData representation of the current clipboard data.
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const char * data(const QByteArray &arr)
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
QVariant imageData() const
Returns a QVariant storing a QImage if the object can return an image; otherwise returns a null varia...
Definition: qmimedata.cpp:442
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571

◆ mimeData()

const QMimeData * QClipboard::mimeData ( Mode  mode = Clipboard) const

Returns a reference to a QMimeData 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. If mode is QClipboard::FindBuffer, the data is retrieved from the search string buffer.

The text(), image(), and pixmap() functions are simpler wrappers for retrieving text, image, and pixmap data.

See also
setMimeData()

Definition at line 134 of file qclipboard_mac.cpp.

Referenced by QTextControl::canPaste(), clipboardData(), QClipboardWatcher::getDataInFormat(), isProcessBeingDebugged(), QTextControlPrivate::mouseReleaseEvent(), QTextControl::paste(), and QMacPasteboard::setMimeData().

135 {
136  if (!supportsMode(mode))
137  return 0;
138  qt_mac_updateScrap(mode);
139  return qt_mac_pasteboard(mode)->mimeData();
140 }
bool supportsMode(Mode mode) const
Returns true if the clipboard supports the clipboard mode speacified by mode; otherwise returns false...
static QMacPasteboard * qt_mac_pasteboard(QClipboard::Mode mode)
QMimeData * mimeData() const
static bool qt_mac_updateScrap(QClipboard::Mode mode)

◆ ownerDestroyed

void QClipboard::ownerDestroyed ( )
privateslot

Internal cleanup for Windows.

Warning
This function is not part of the public interface.

Definition at line 108 of file qclipboard_mac.cpp.

Referenced by clipboardData(), and isProcessBeingDebugged().

109 {
110 }

◆ ownsClipboard()

bool QClipboard::ownsClipboard ( ) const

Returns true if this clipboard object owns the clipboard data; otherwise returns false.

Definition at line 585 of file qclipboard.cpp.

586 {
587  return ownsMode(Clipboard);
588 }
bool ownsMode(Mode mode) const
Returns true if the clipboard supports the clipboard data speacified by mode; otherwise returns false...

◆ ownsFindBuffer()

bool QClipboard::ownsFindBuffer ( ) const

Returns true if this clipboard object owns the find buffer data; otherwise returns false.

Since
4.2

Definition at line 608 of file qclipboard.cpp.

609 {
610  return ownsMode(FindBuffer);
611 }
bool ownsMode(Mode mode) const
Returns true if the clipboard supports the clipboard data speacified by mode; otherwise returns false...

◆ ownsMode()

bool QClipboard::ownsMode ( Mode  mode) const
private

Returns true if the clipboard supports the clipboard data speacified by mode; otherwise returns false.

Warning
This function is not part of the public interface.

Definition at line 156 of file qclipboard_mac.cpp.

Referenced by clipboardData(), and isProcessBeingDebugged().

157 {
158  Q_UNUSED(mode);
159  return false;
160 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ ownsSelection()

bool QClipboard::ownsSelection ( ) const

Returns true if this clipboard object owns the mouse selection data; otherwise returns false.

Definition at line 594 of file qclipboard.cpp.

595 {
596  return ownsMode(Selection);
597 }
bool ownsMode(Mode mode) const
Returns true if the clipboard supports the clipboard data speacified by mode; otherwise returns false...

◆ pixmap()

QPixmap QClipboard::pixmap ( Mode  mode = Clipboard) 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.

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() mimeData() QPixmap::convertFromImage()

Definition at line 440 of file qclipboard.cpp.

441 {
442  const QMimeData *data = mimeData(mode);
443  return data ? qvariant_cast<QPixmap>(data->imageData()) : QPixmap();
444 }
const QMimeData * mimeData(Mode mode=Clipboard) const
Returns a reference to a QMimeData representation of the current clipboard data.
static const char * data(const QByteArray &arr)
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
QVariant imageData() const
Returns a QVariant storing a QImage if the object can return an image; otherwise returns a null varia...
Definition: qmimedata.cpp:442
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71

◆ selectionChanged

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 and Mac OS X don't support selections.

See also
dataChanged(), findBufferChanged(), changed()

◆ setImage()

void QClipboard::setImage ( const QImage image,
Mode  mode = Clipboard 
)

Copies the 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:

QMimeData *data = new QMimeData;
clipboard->setMimeData(data, mode);
See also
image(), setPixmap() setMimeData()

Definition at line 418 of file qclipboard.cpp.

419 {
420  QMimeData *data = new QMimeData;
421  data->setImageData(image);
422  setMimeData(data, mode);
423 }
void setImageData(const QVariant &image)
Sets the data in the object to the given image.
Definition: qmimedata.cpp:459
void setMimeData(QMimeData *data, Mode mode=Clipboard)
Sets the clipboard data to src.
static const char * data(const QByteArray &arr)
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57

◆ setMimeData()

void QClipboard::setMimeData ( QMimeData src,
Mode  mode = Clipboard 
)

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 setMimeData() 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 stored in the global clipboard. If mode is QClipboard::Selection, the data is stored in the global mouse selection. If mode is QClipboard::FindBuffer, the data is stored in the search string buffer.

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

See also
mimeData()

Definition at line 142 of file qclipboard_mac.cpp.

Referenced by QTextControlPrivate::_q_copyLink(), clear(), clipboardData(), QTextControl::copy(), QClipboardWatcher::getDataInFormat(), QTextControlPrivate::setClipboardSelection(), QMacPasteboard::sync(), and ~QClipboard().

143 {
144  if (!supportsMode(mode))
145  return;
146  qt_mac_updateScrap(mode);
147  qt_mac_pasteboard(mode)->setMimeData(src);
148  emitChanged(mode);
149 }
void emitChanged(Mode mode)
Emits the appropriate changed signal for mode.
Definition: qclipboard.cpp:640
bool supportsMode(Mode mode) const
Returns true if the clipboard supports the clipboard mode speacified by mode; otherwise returns false...
void setMimeData(QMimeData *mime)
static QMacPasteboard * qt_mac_pasteboard(QClipboard::Mode mode)
static bool qt_mac_updateScrap(QClipboard::Mode mode)

◆ setPixmap()

void QClipboard::setPixmap ( const QPixmap pixmap,
Mode  mode = Clipboard 
)

Copies pixmap into the clipboard.

Note that this is slower than setImage() because it needs to convert the QPixmap to a QImage first.

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() setMimeData()

Definition at line 459 of file qclipboard.cpp.

460 {
461  QMimeData *data = new QMimeData;
462  data->setImageData(pixmap);
463  setMimeData(data, mode);
464 }
void setImageData(const QVariant &image)
Sets the data in the object to the given image.
Definition: qmimedata.cpp:459
void setMimeData(QMimeData *data, Mode mode=Clipboard)
Sets the clipboard data to src.
static const char * data(const QByteArray &arr)
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57

◆ setText()

void QClipboard::setText ( const QString text,
Mode  mode = Clipboard 
)

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. If mode is QClipboard::FindBuffer, the text is stored in the search string buffer.

See also
text(), setMimeData()

Definition at line 375 of file qclipboard.cpp.

Referenced by clipboardData(), QLineControl::copy(), QmlJSDebugger::ToolBarColorBox::copyColorToClipboard(), QAccessibleTextWidget::copyText(), QAccessibleSimpleEditableTextInterface::copyText(), QAccessibleTextWidget::cutText(), QAccessibleSimpleEditableTextInterface::cutText(), QMessageBox::keyPressEvent(), and QAbstractItemView::keyPressEvent().

376 {
377  QMimeData *data = new QMimeData;
378  data->setText(text);
379  setMimeData(data, mode);
380 }
void setMimeData(QMimeData *data, Mode mode=Clipboard)
Sets the clipboard data to src.
static const char * data(const QByteArray &arr)
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
void setText(const QString &text)
Sets text as the plain text (MIME type text/plain) used to represent the data.
Definition: qmimedata.cpp:377

◆ supportsFindBuffer()

bool QClipboard::supportsFindBuffer ( ) const

Returns true if the clipboard supports a separate search buffer; otherwise returns false.

Definition at line 576 of file qclipboard.cpp.

577 {
578  return supportsMode(FindBuffer);
579 }
bool supportsMode(Mode mode) const
Returns true if the clipboard supports the clipboard mode speacified by mode; otherwise returns false...

◆ supportsMode()

bool QClipboard::supportsMode ( Mode  mode) const
private

Returns true if the clipboard supports the clipboard mode speacified by mode; otherwise returns false.

Warning
This function is not part of the public interface.

Definition at line 151 of file qclipboard_mac.cpp.

Referenced by clear(), clipboardData(), isProcessBeingDebugged(), mimeData(), and setMimeData().

152 {
153  return (mode == Clipboard || mode == FindBuffer);
154 }

◆ supportsSelection()

bool QClipboard::supportsSelection ( ) const

Returns true if the clipboard supports mouse selection; otherwise returns false.

Definition at line 567 of file qclipboard.cpp.

Referenced by QTextControlPrivate::setClipboardSelection().

568 {
569  return supportsMode(Selection);
570 }
bool supportsMode(Mode mode) const
Returns true if the clipboard supports the clipboard mode speacified by mode; otherwise returns false...

◆ text() [1/2]

QString QClipboard::text ( Mode  mode = Clipboard) const

Returns the clipboard text as plain text, or an empty 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. If mode is QClipboard::FindBuffer, the text is retrieved from the search string buffer.

See also
setText(), mimeData()

Definition at line 357 of file qclipboard.cpp.

Referenced by clipboardData(), QLineEdit::createStandardContextMenu(), QDeclarativeTextInputPrivate::init(), QLineControl::paste(), QAccessibleTextWidget::pasteText(), and QDeclarativeTextInput::q_canPasteChanged().

358 {
359  const QMimeData *data = mimeData(mode);
360  return data ? data->text() : QString();
361 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
const QMimeData * mimeData(Mode mode=Clipboard) const
Returns a reference to a QMimeData representation of the current clipboard data.
QString text() const
Returns a plain text (MIME type text/plain) representation of the data.
Definition: qmimedata.cpp:364
static const char * data(const QByteArray &arr)
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57

◆ text() [2/2]

QString QClipboard::text ( QString subtype,
Mode  mode = Clipboard 
) const

Returns the clipboard text in subtype subtype, or an empty string if the clipboard does not contain any text.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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".

Note that calling this function repeatedly, for instance from a key event handler, may be slow. In such cases, you should use the dataChanged() signal instead.

See also
setText(), mimeData()

Definition at line 307 of file qclipboard.cpp.

308 {
309  const QMimeData *const data = mimeData(mode);
310  if (!data)
311  return QString();
312 
313  const QStringList formats = data->formats();
314  if (subtype.isEmpty()) {
315  if (formats.contains(QLatin1String("text/plain")))
316  subtype = QLatin1String("plain");
317  else {
318  for (int i = 0; i < formats.size(); ++i)
319  if (formats.at(i).startsWith(QLatin1String("text/"))) {
320  subtype = formats.at(i).mid(5);
321  break;
322  }
323  if (subtype.isEmpty())
324  return QString();
325  }
326  } else if (!formats.contains(QLatin1String("text/") + subtype)) {
327  return QString();
328  }
329 
330  const QByteArray rawData = data->data(QLatin1String("text/") + subtype);
331 
332 #ifndef QT_NO_TEXTCODEC
333  QTextCodec* codec = QTextCodec::codecForMib(106); // utf-8 is default
334  if (subtype == QLatin1String("html"))
335  codec = QTextCodec::codecForHtml(rawData, codec);
336  else
337  codec = QTextCodec::codecForUtfText(rawData, codec);
338  return codec->toUnicode(rawData);
339 #else //QT_NO_TEXTCODEC
340  return rawData;
341 #endif //QT_NO_TEXTCODEC
342 }
virtual QStringList formats() const
Returns a list of formats supported by the object.
Definition: qmimedata.cpp:579
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static QTextCodec * codecForHtml(const QByteArray &ba)
Tries to detect the encoding of the provided snippet of HTML in the given byte array, ba, by checking the BOM (Byte Order Mark) and the content-type meta header and returns a QTextCodec instance that is capable of decoding the html to unicode.
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QByteArray data(const QString &mimetype) const
Returns the data stored in the object in the format described by the MIME type specified by mimeType...
Definition: qmimedata.cpp:524
The QString class provides a Unicode character string.
Definition: qstring.h:83
const QMimeData * mimeData(Mode mode=Clipboard) const
Returns a reference to a QMimeData representation of the current clipboard data.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static const char * data(const QByteArray &arr)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
static QTextCodec * codec(MYSQL *mysql)
Definition: qsql_mysql.cpp:220
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
static QTextCodec * codecForMib(int mib)
Returns the QTextCodec which matches the MIBenum mib.
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
QString toUnicode(const QByteArray &) const
Converts a from the encoding of this codec to Unicode, and returns the result in a QString...
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static QTextCodec * codecForUtfText(const QByteArray &ba)
Tries to detect the encoding of the provided snippet ba by using the BOM (Byte Order Mark) and return...
The QTextCodec class provides conversions between text encodings.
Definition: qtextcodec.h:62

Friends and Related Functions

◆ QApplication

friend class QApplication
friend

Definition at line 110 of file qclipboard.h.

◆ QApplicationPrivate

friend class QApplicationPrivate
friend

Definition at line 111 of file qclipboard.h.

◆ QBaseApplication

friend class QBaseApplication
friend

Definition at line 112 of file qclipboard.h.

◆ QDragManager

friend class QDragManager
friend

Definition at line 113 of file qclipboard.h.

◆ QMimeSource

friend class QMimeSource
friend

Definition at line 114 of file qclipboard.h.

◆ QPlatformClipboard

friend class QPlatformClipboard
friend

Definition at line 115 of file qclipboard.h.


The documentation for this class was generated from the following files: