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  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QMacCocoaViewContainer Class Reference

The QMacCocoaViewContainer class provides a widget for Mac OS X that can be used to wrap arbitrary Cocoa views (i.e., NSView subclasses) and insert them into Qt hierarchies. More...

 #include <QMacCocoaViewContainer>

Inherits: QWidget.

This class was introduced in Qt 4.5.

Public Functions

QMacCocoaViewContainer ( void * cocoaViewToWrap, QWidget * parent = 0 )
virtual ~QMacCocoaViewContainer ()
void * cocoaView () const
void setCocoaView ( void * cocoaViewToWrap )
  • 217 public functions inherited from QWidget
  • 29 public functions inherited from QObject
  • 13 public functions inherited from QPaintDevice

Additional Inherited Members

  • 58 properties inherited from QWidget
  • 1 property inherited from QObject
  • 19 public slots inherited from QWidget
  • 1 public slot inherited from QObject
  • 1 signal inherited from QWidget
  • 1 signal inherited from QObject
  • 4 static public members inherited from QWidget
  • 5 static public members inherited from QObject
  • 37 protected functions inherited from QWidget
  • 7 protected functions inherited from QObject
  • 1 protected function inherited from QPaintDevice
  • 1 protected slot inherited from QWidget

Detailed Description

The QMacCocoaViewContainer class provides a widget for Mac OS X that can be used to wrap arbitrary Cocoa views (i.e., NSView subclasses) and insert them into Qt hierarchies.

While Qt offers a lot of classes for writing your application, Apple's Cocoa framework offers lots of functionality that is not currently in Qt or may never end up in Qt. Using QMacCocoaViewContainer, it is possible to put an arbitrary NSView-derived class from Cocoa and put it in a Qt hierarchy. Depending on how comfortable you are with using objective-C, you can use QMacCocoaViewContainer directly, or subclass it to wrap further functionality of the underlying NSView.

QMacCocoaViewContainer works regardless if Qt is built against Carbon or Cocoa. However, QCocoaContainerView requires Mac OS X 10.5 or better to be used with Carbon.

It should be also noted that at the low level on Mac OS X, there is a difference between windows (top-levels) and view (widgets that are inside a window). For this reason, make sure that the NSView that you are wrapping doesn't end up as a top-level. The best way to ensure this is to make sure you always have a parent and not set the parent to 0.

If you are using QMacCocoaViewContainer as a sub-class and are mixing and matching objective-C with C++ (a.k.a. objective-C++). It is probably simpler to have your file end with .mm than .cpp. Most Apple tools will correctly identify the source as objective-C++.

QMacCocoaViewContainer requires knowledge of how Cocoa works, especially in regard to its reference counting (retain/release) nature. It is noted in the functions below if there is any change in the reference count. Cocoa views often generate temporary objects that are released by an autorelease pool. If this is done outside of a running event loop, it is up to the developer to provide the autorelease pool.

The following is a snippet of subclassing QMacCocoaViewContainer to wrap a NSSearchField.

 SearchWidget::SearchWidget(QWidget *parent)
     : QMacCocoaViewContainer(0, parent)
 {
     // Many Cocoa objects create temporary autorelease objects,
     // so create a pool to catch them.
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

     // Create the NSSearchField, set it on the QCocoaViewContainer.
     NSSearchField *search = [[NSSearchField alloc] init];
     setCocoaView(search);

     // Use a Qt menu for the search field menu.
     QMenu *qtMenu = createMenu(this);
     NSMenu *nsMenu = qtMenu->macMenu(0);
     [[search cell] setSearchMenuTemplate:nsMenu];

     // Release our reference, since our super class takes ownership and we
     // don't need it anymore.
     [search release];

     // Clean up our pool as we no longer need it.
     [pool release];
 }

Member Function Documentation

QMacCocoaViewContainer::QMacCocoaViewContainer ( void * cocoaViewToWrap, QWidget * parent = 0 )

Create a new QMacCocoaViewContainer using the NSView pointer in cocoaViewToWrap with parent, parent. QMacCocoaViewContainer will retain cocoaViewToWrap.

cocoaViewToWrap is a void pointer that allows the header to be included with C++ source.

QMacCocoaViewContainer::~QMacCocoaViewContainer () [virtual]

Destroy the QMacCocoaViewContainer and release the wrapped view.

void * QMacCocoaViewContainer::cocoaView () const

Returns the NSView that has been set on this container. The returned view has been autoreleased, so you will need to retain it if you want to make use of it.

See also setCocoaView().

void QMacCocoaViewContainer::setCocoaView ( void * cocoaViewToWrap )

Sets the NSView to contain to be cocoaViewToWrap and retains it. If this container already had a view set, it will release the previously set view.

See also cocoaView().

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 53
  2. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  3. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  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 Developer Network au hasard

Logo

Livre blanc de l'outillage de Qt Quick

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. 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 4.7
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