Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QClipboard Class

TheQClipboard class provides access to the window system clipboard.More...

Header:#include <QClipboard>
Inherits:QObject

Public Types

enumMode { Clipboard, Selection, FindBuffer }

Public Functions

voidclear(Mode mode = Clipboard)
QImageimage(Mode mode = Clipboard) const
const QMimeData *mimeData(Mode mode = Clipboard) const
boolownsClipboard() const
boolownsFindBuffer() const
boolownsSelection() const
QPixmappixmap(Mode mode = Clipboard) const
voidsetImage(const QImage & image, Mode mode = Clipboard)
voidsetMimeData(QMimeData * src, Mode mode = Clipboard)
voidsetPixmap(const QPixmap & pixmap, Mode mode = Clipboard)
voidsetText(const QString & text, Mode mode = Clipboard)
boolsupportsFindBuffer() const
boolsupportsSelection() const
QStringtext(Mode mode = Clipboard) const
QStringtext(QString & subtype, Mode mode = Clipboard) const
  • 29 public functions inherited fromQObject

Signals

voidchanged(QClipboard::Mode mode)
voiddataChanged()
voidfindBufferChanged()
voidselectionChanged()

Reimplemented Protected Functions

virtual boolevent(QEvent * e)
  • 8 protected functions inherited fromQObject

Additional Inherited Members

  • 1 property inherited fromQObject
  • 1 public slot inherited fromQObject
  • 7 static public members inherited fromQObject
  • 8 protected functions inherited fromQObject

Detailed Description

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"));    }

Notes for X11 Users

  • The X11 Window System has the concept of a separate selection and clipboard. When text is selected, it is 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 used to paste the global mouse selection.
  • 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.
  • 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.
  • Since there is no standard way to copy and paste files between applications on X11, various MIME types and conventions are currently in use. For instance, Nautilus expects files to be supplied with ax-special/gnome-copied-files MIME type with data beginning with the cut/copy action, a newline character, and the URL of the file.

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 theFindBuffer mode.

Notes for Windows and Mac OS X Users

  • Windows and Mac OS X do not support the global mouse selection; they only supports the global clipboard, i.e. they only add text to the clipboard when an explicit copy or cut is made.
  • Windows and Mac OS X does not have the concept of ownership; the clipboard is a fully global resource so all applications are notified of changes.

See alsoQApplication.

Member Type Documentation

enum QClipboard::Mode

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

ConstantValueDescription
QClipboard::Clipboard0indicates that data should be stored and retrieved from the global clipboard.
QClipboard::Selection1indicates 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::FindBuffer2indicates 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().

Member Function Documentation

[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().

void QClipboard::clear(Mode mode = Clipboard)

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

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.

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

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

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

bool QClipboard::ownsClipboard() const

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

bool QClipboard::ownsFindBuffer() const

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

This function was introduced in Qt 4.2.

bool QClipboard::ownsSelection() const

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

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.

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

void QClipboard::setImage(constQImage & image,Mode mode = Clipboard)

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

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

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

void QClipboard::setPixmap(constQPixmap & pixmap,Mode mode = Clipboard)

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

void QClipboard::setText(constQString & text,Mode mode = Clipboard)

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

bool QClipboard::supportsFindBuffer() const

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

bool QClipboard::supportsSelection() const

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

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.

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

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

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.

See alsosetText() andmimeData().

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


[8]ページ先頭

©2009-2025 Movatter.jp