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  ·  Classes  ·  Annotées  ·  Hiérarchie  ·  Fonctions  ·  Structure  · 

QCustomMenuItem Class Reference


The QCustomMenuItem class is an abstract base class for custom menu items in popup menus. More...

#include <qmenudata.h>

Inherits Qt.

List of all member functions.

Public Members

  • QCustomMenuItem () 
  • virtual ~QCustomMenuItem () 
  • virtual bool fullSpan () const
  • virtual bool isSeparator () const
  • virtual void setFont ( const QFont & font ) 
  • virtual void paint ( QPainter * p, const QColorGroup & cg, bool act, bool enabled, int x, int y, int w, int h ) 
  • virtual QSize sizeHint () 

Detailed Description

The QCustomMenuItem class is an abstract base class for custom menu items in popup menus.

A custom menu item is a menu item that is defined by two purely virtual functions, paint() and sizeHint(). The size hint tells the menu how much space it needs to reserve for this item, whereas paint is called whenever the item needs painting.

This simply mechanism gives applications the possibility to create all kinds of application specific menu items. Examples are items showing different fonts in a word processor, or menus that allow the selection of drawing utilities in a vector drawing program.

A custom item is inserted into a popup menu with QPopupMenu::insertItem().

Per default, a custom item can also have an icon set and/or an accelerator key. You can, however, reimplement fullSpan() to return TRUE if you want the item to span the entire popup menu width. This is in particular useful for labels.

If you want the custom item to be treated as a separator only, reimplement isSeparator() to return TRUE.

Note that you can also insert pixmaps or bitmaps as items into a popup menu. A custom menu item, however, offers even more flexibility and - which is especially important under windows style - the possibility to draw the item with a different color when it is highlighted.

menu/menu.cpp shows a simply example how custom menu items can be used.

Please note: QCustomMenu items will not recognize menu shortcuts (text with ampersands in it).

See also QMenuData and QPopupMenu.


Member Function Documentation

QCustomMenuItem::QCustomMenuItem ()

Constructs a QCustomMenuItem.

QCustomMenuItem::~QCustomMenuItem () [virtual]

Destructs a QCustomMenuItem.

bool QCustomMenuItem::fullSpan () const [virtual]

Returns whether this item wants to span the entire popup menu width. The default is FALSE, meaning that the menu may show an icon and/or an accelerator key for this item as well.

bool QCustomMenuItem::isSeparator () const [virtual]

Returns whether this item is just a separator.

void QCustomMenuItem::paint ( QPainter * p, const QColorGroup & cg, bool act, bool enabled, int x, int y, int w, int h ) [virtual]

Paints this item. When this function is invoked, the painter p is set to the right font and the right foreground color suitable for a menu item text. The item is active according to act and enabled/disabled according to enabled. The geometry values x, y, w and h specify where to draw the item.

Do not draw any background, this has already been done by the popup menu according to the current gui style.

void QCustomMenuItem::setFont ( const QFont & ) [virtual]

Sets the font of the custom menu item.

This function is called whenever the font in the popup menu changes. For menu items that show their own individual font entry, you want to ignore this.

QSize QCustomMenuItem::sizeHint () [virtual]

Returns the size hint of this item.


Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):


This file is part of the Qt toolkit, copyright © 1995-2005 Trolltech, all rights reserved.

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 2.3
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