
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQClipboard class provides access to the window system clipboard.More...
| Header: | #include <QClipboard> |
| Inherits: | QObject |
| enum | Mode { Clipboard, Selection, FindBuffer } |
| void | clear(Mode mode = Clipboard) |
| QImage | image(Mode mode = Clipboard) const |
| const QMimeData * | mimeData(Mode mode = Clipboard) const |
| bool | ownsClipboard() const |
| bool | ownsFindBuffer() const |
| bool | ownsSelection() const |
| QPixmap | pixmap(Mode mode = Clipboard) const |
| void | setImage(const QImage & image, Mode mode = Clipboard) |
| void | setMimeData(QMimeData * src, Mode mode = Clipboard) |
| void | setPixmap(const QPixmap & pixmap, Mode mode = Clipboard) |
| void | setText(const QString & text, Mode mode = Clipboard) |
| bool | supportsFindBuffer() const |
| bool | supportsSelection() const |
| QString | text(Mode mode = Clipboard) const |
| QString | text(QString & subtype, Mode mode = Clipboard) const |
| void | changed(QClipboard::Mode mode) |
| void | dataChanged() |
| void | findBufferChanged() |
| void | selectionChanged() |
| virtual bool | event(QEvent * e) |
TheQClipboard 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 thatQDrag does, and uses similar mechanisms. For advanced clipboard usage readDrag and Drop.
There is a singleQClipboard object in an application, accessible asQApplication::clipboard().
Example:
QClipboard*clipboard=QApplication::clipboard();QString originalText= clipboard->text();...clipboard->setText(newText);
QClipboard features some convenience functions to access common data types:setText() allows the exchange of Unicode text andsetPixmap() andsetImage() allows the exchange of QPixmaps and QImages between applications. ThesetMimeData() function is the ultimate in flexibility: it allows you to add anyQMimeData into the clipboard. There are corresponding getters for each of these, e.g.text(),image() andpixmap(). You can clear the clipboard by callingclear().
A typical example of the use of these functions follows:
void DropArea::paste(){constQClipboard*clipboard=QApplication::clipboard();constQMimeData*mimeData= clipboard->mimeData();if (mimeData->hasImage()) { setPixmap(qvariant_cast<QPixmap>(mimeData->imageData())); }elseif (mimeData->hasHtml()) { setText(mimeData->html()); setTextFormat(Qt::RichText); }elseif (mimeData->hasText()) { setText(mimeData->text()); setTextFormat(Qt::PlainText); }else { setText(tr("Cannot display data")); }
x-special/gnome-copied-files MIME type with data beginning with the cut/copy action, a newline character, and the URL of the file.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 theFindBuffer mode.
See alsoQApplication.
This enum type is used to control which part of the system clipboard is used byQClipboard::mimeData(),QClipboard::setMimeData() and related functions.
| Constant | Value | Description |
|---|---|---|
QClipboard::Clipboard | 0 | indicates that data should be stored and retrieved from the global clipboard. |
QClipboard::Selection | 1 | indicates that data should be stored and retrieved from the global mouse selection. Support forSelection is provided only on systems with a global mouse selection (e.g. X11). |
QClipboard::FindBuffer | 2 | indicates that data should be stored and retrieved from the Find buffer. This mode is used for holding search strings on Mac OS X. |
See alsoQClipboard::supportsSelection().
[signal]void QClipboard::changed(QClipboard::Mode mode)This signal is emitted when the data for the given clipboardmode is changed.
This function was introduced in Qt 4.2.
See alsodataChanged(),selectionChanged(), andfindBufferChanged().
Clear the clipboard contents.
Themode argument is used to control which part of the system clipboard is used. Ifmode isQClipboard::Clipboard, this function clears the global clipboard contents. Ifmode isQClipboard::Selection, this function clears the global mouse selection contents. Ifmode isQClipboard::FindBuffer, this function clears the search string buffer.
See alsoQClipboard::Mode andsupportsSelection().
[signal]void QClipboard::dataChanged()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 alsofindBufferChanged(),selectionChanged(), andchanged().
[virtual protected]bool QClipboard::event(QEvent * e)Reimplemented fromQObject::event().
[signal]void QClipboard::findBufferChanged()This signal is emitted when the find buffer is changed. 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.
This function was introduced in Qt 4.2.
See alsodataChanged(),selectionChanged(), andchanged().
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.
Themode argument is used to control which part of the system clipboard is used. Ifmode isQClipboard::Clipboard, the image is retrieved from the global clipboard. Ifmode isQClipboard::Selection, the image is retrieved from the global mouse selection.
See alsosetImage(),pixmap(),mimeData(), andQImage::isNull().
Returns a reference to aQMimeData representation of the current clipboard data.
Themode argument is used to control which part of the system clipboard is used. Ifmode isQClipboard::Clipboard, the data is retrieved from the global clipboard. Ifmode isQClipboard::Selection, the data is retrieved from the global mouse selection. Ifmode isQClipboard::FindBuffer, the data is retrieved from the search string buffer.
Thetext(),image(), andpixmap() functions are simpler wrappers for retrieving text, image, and pixmap data.
See alsosetMimeData().
Returns true if this clipboard object owns the clipboard data; otherwise returns false.
Returns true if this clipboard object owns the find buffer data; otherwise returns false.
This function was introduced in Qt 4.2.
Returns true if this clipboard object owns the mouse selection data; otherwise returns false.
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.
Themode argument is used to control which part of the system clipboard is used. Ifmode isQClipboard::Clipboard, the pixmap is retrieved from the global clipboard. Ifmode isQClipboard::Selection, the pixmap is retrieved from the global mouse selection.
See alsosetPixmap(),image(),mimeData(), andQPixmap::convertFromImage().
[signal]void QClipboard::selectionChanged()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 alsodataChanged(),findBufferChanged(), andchanged().
Copies theimage into the clipboard.
Themode argument is used to control which part of the system clipboard is used. Ifmode isQClipboard::Clipboard, the image is stored in the global clipboard. Ifmode isQClipboard::Selection, the data is stored in the global mouse selection.
This is shorthand for:
QMimeData*data=newQMimeData;data->setImageData(image);clipboard->setMimeData(data, mode);
See alsoimage(),setPixmap(), andsetMimeData().
Sets the clipboard data tosrc. Ownership of the data is transferred to the clipboard. If you want to remove the data either callclear() or call setMimeData() again with new data.
Themode argument is used to control which part of the system clipboard is used. Ifmode isQClipboard::Clipboard, the data is stored in the global clipboard. Ifmode isQClipboard::Selection, the data is stored in the global mouse selection. Ifmode isQClipboard::FindBuffer, the data is stored in the search string buffer.
ThesetText(),setImage() andsetPixmap() functions are simpler wrappers for setting text, image and pixmap data respectively.
See alsomimeData().
Copiespixmap into the clipboard. Note that this is slower thansetImage() because it needs to convert theQPixmap to aQImage first.
Themode argument is used to control which part of the system clipboard is used. Ifmode isQClipboard::Clipboard, the pixmap is stored in the global clipboard. Ifmode isQClipboard::Selection, the pixmap is stored in the global mouse selection.
See alsopixmap(),setImage(), andsetMimeData().
Copiestext into the clipboard as plain text.
Themode argument is used to control which part of the system clipboard is used. Ifmode isQClipboard::Clipboard, the text is stored in the global clipboard. Ifmode isQClipboard::Selection, the text is stored in the global mouse selection. Ifmode isQClipboard::FindBuffer, the text is stored in the search string buffer.
See alsotext() andsetMimeData().
Returns true if the clipboard supports a separate search buffer; otherwise returns false.
Returns true if the clipboard supports mouse selection; otherwise returns false.
Returns the clipboard text as plain text, or an empty string if the clipboard does not contain any text.
Themode argument is used to control which part of the system clipboard is used. Ifmode isQClipboard::Clipboard, the text is retrieved from the global clipboard. Ifmode isQClipboard::Selection, the text is retrieved from the global mouse selection. Ifmode isQClipboard::FindBuffer, the text is retrieved from the search string buffer.
See alsosetText() andmimeData().
This is an overloaded function.
Returns the clipboard text in subtypesubtype, or an empty string if the clipboard does not contain any text. Ifsubtype is null, any subtype is acceptable, andsubtype is set to the chosen subtype.
Themode argument is used to control which part of the system clipboard is used. Ifmode isQClipboard::Clipboard, the text is retrieved from the global clipboard. Ifmode isQClipboard::Selection, the text is retrieved from the global mouse selection.
Common values forsubtype 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 thedataChanged() signal instead.
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.