Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Fonctions  · 

QClipboard Class Reference

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

#include <qclipboard.h>

Inherits QObject.

List of all member functions.

Public Members

Signals


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 QDragObject does, and uses similar mechanisms. For advanced clipboard usage read the drag-and-drop documentation.

There is a single QClipboard object in an application, and you can access it using QApplication::clipboard().

Example:

    QClipboard *cb = QApplication::clipboard();
    QString text;

    // Copy text from the clipboard (paste)
    text = cb->text();
    if ( text )
        qDebug( "The clipboard contains: %s", text );

    // Copy text into the clipboard
    cb->setText( "This text can be pasted by other programs" );
    

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 setData() function is the ultimate in flexibility: it allows you to add any QMimeSource 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().

The underlying clipboards of the X Window system and MS Windows differ. The X Window system has a concept of selection -- when text is selected, it is immediately available in the selection buffer; MS Windows only adds text to the clipboard when an explicit copy or cut is made. The X Window system also has a concept of ownership; if you change the selection within a window, X11 will only notify the owner and the previous owner of the change; in MS Windows the clipboard is a fully global resource so all applications are notified of changes. 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 Function Documentation

void QClipboard::clear ()

Clears the clipboard contents.

QMimeSource * QClipboard::data () const

Returns a reference to a QMimeSource representation of the current clipboard data.

void QClipboard::dataChanged () [signal]

This signal is emitted when the clipboard data is changed.

QImage QClipboard::image () 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.

See also setImage(), pixmap(), data() and QImage::isNull().

bool QClipboard::ownsClipboard () const

Returns TRUE if this clipboard object owns the clipboard data; otherwise returns FALSE.

bool QClipboard::ownsSelection () const

Returns TRUE if this clipboard object owns the mouse selection data; otherwise returns FALSE.

QPixmap QClipboard::pixmap () 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.

See also setPixmap(), image(), data() and QPixmap::convertFromImage().

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

Returns the selection mode.

See also setSelectionMode() and supportsSelection().

void QClipboard::setData ( QMimeSource * src )

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 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() and setPixmap() functions are simpler wrappers for setting text and image data respectively.

void QClipboard::setImage ( const QImage & image )

Copies image into the clipboard.

This is shorthand for:

        setData(new QImageDrag(image))
    

See also image(), setPixmap() and setData().

void QClipboard::setPixmap ( const QPixmap & pixmap )

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

See also pixmap(), setImage() and setData().

void QClipboard::setSelectionMode ( bool enable )

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 )

Copies text into the clipboard as plain text.

See also text() and setData().

bool QClipboard::supportsSelection () const

Returns TRUE if the clipboard supports mouse selection; otherwise returns FALSE.

QString QClipboard::text ( QCString & subtype ) const

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.

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.

Returns the clipboard text as plain text, or a null string if the clipboard does not contain any text.

See also setText(), data() and QString::operator!().


This file is part of the Qt toolkit. Copyright © 1995-2002 Trolltech. All Rights Reserved.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 64
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le Qt Labs au hasard

Logo

Le moteur de rendu OpenVG

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 3.0
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web