Qt 4.8
Public Types | Public Functions | Public Variables | Protected Functions | List of all members
QStyleOptionMenuItem Class Reference

The QStyleOptionMenuItem class is used to describe the parameter necessary for drawing a menu item. More...

#include <qstyleoption.h>

Inheritance diagram for QStyleOptionMenuItem:
QStyleOption

Public Types

enum  CheckType { NotCheckable, Exclusive, NonExclusive }
 This enum is used to indicate whether or not a check mark should be drawn for the item, or even if it should be drawn at all. More...
 
enum  MenuItemType {
  Normal, DefaultItem, Separator, SubMenu,
  Scroller, TearOff, Margin, EmptyArea
}
 This enum indicates the type of menu item that the structure describes. More...
 
enum  StyleOptionType { Type = SO_MenuItem }
 This enum is used to hold information about the type of the style option, and is defined for each QStyleOption subclass. More...
 
enum  StyleOptionVersion { Version = 1 }
 This enum is used to hold information about the version of the style option, and is defined for each QStyleOption subclass. More...
 
- Public Types inherited from QStyleOption
enum  OptionType {
  SO_Default, SO_FocusRect, SO_Button, SO_Tab,
  SO_MenuItem, SO_Frame, SO_ProgressBar, SO_ToolBox,
  SO_Header, SO_Q3DockWindow, SO_DockWidget, SO_Q3ListViewItem,
  SO_ViewItem, SO_TabWidgetFrame, SO_TabBarBase, SO_RubberBand,
  SO_ToolBar, SO_GraphicsItem, SO_Complex = 0xf0000, SO_Slider,
  SO_SpinBox, SO_ToolButton, SO_ComboBox, SO_Q3ListView,
  SO_TitleBar, SO_GroupBox, SO_SizeGrip, SO_CustomBase = 0xf00,
  SO_ComplexCustomBase = 0xf000000
}
 This enum is used internally by QStyleOption, its subclasses, and qstyleoption_cast() to determine the type of style option. More...
 
enum  StyleOptionType { Type = SO_Default }
 This enum is used to hold information about the type of the style option, and is defined for each QStyleOption subclass. More...
 
enum  StyleOptionVersion { Version = 1 }
 This enum is used to hold information about the version of the style option, and is defined for each QStyleOption subclass. More...
 

Public Functions

 QStyleOptionMenuItem ()
 Constructs a QStyleOptionMenuItem, initializing the members variables to their default values. More...
 
 QStyleOptionMenuItem (const QStyleOptionMenuItem &other)
 Constructs a copy of the other style option. More...
 
- Public Functions inherited from QStyleOption
void init (const QWidget *w)
 Use initFrom(widget) instead. More...
 
void initFrom (const QWidget *w)
 
QStyleOptionoperator= (const QStyleOption &other)
 Assign other to this QStyleOption. More...
 
 QStyleOption (int version=QStyleOption::Version, int type=SO_Default)
 Constructs a QStyleOption with the specified version and type. More...
 
 QStyleOption (const QStyleOption &other)
 Constructs a copy of other. More...
 
 ~QStyleOption ()
 Destroys this style option object. More...
 

Public Variables

bool checked
 whether the menu item is checked or not More...
 
CheckType checkType
 the type of checkmark of the menu item More...
 
QFont font
 the font used for the menu item text More...
 
QIcon icon
 the icon for the menu item More...
 
int maxIconWidth
 the maximum icon width for the icon in the menu item More...
 
bool menuHasCheckableItems
 whether the menu as a whole has checkable items or not More...
 
MenuItemType menuItemType
 the type of menu item More...
 
QRect menuRect
 the rectangle for the entire menu More...
 
int tabWidth
 the tab width for the menu item More...
 
QString text
 the text for the menu item More...
 
- Public Variables inherited from QStyleOption
Qt::LayoutDirection direction
 the text layout direction that should be used when drawing text in the control More...
 
QFontMetrics fontMetrics
 the font metrics that should be used when drawing text in the control More...
 
QPalette palette
 the palette that should be used when painting the control More...
 
QRect rect
 the area that should be used for various calculations and painting More...
 
QStyle::State state
 the style flags that are used when drawing the control More...
 
int type
 the option type of the style option More...
 
int version
 the version of the style option More...
 

Protected Functions

 QStyleOptionMenuItem (int version)
 

Additional Inherited Members

Detailed Description

The QStyleOptionMenuItem class is used to describe the parameter necessary for drawing a menu item.

QStyleOptionMenuItem contains all the information that QStyle functions need to draw the menu items from QMenu . It is also used for drawing other menu-related widgets.

For performance reasons, the access to the member variables is direct (i.e., using the . or -> operator). This low-level feel makes the structures straightforward to use and emphasizes that these are simply parameters used by the style functions.

For an example demonstrating how style options can be used, see the widgets/styles{Styles} example.

See also
QStyleOption

Definition at line 435 of file qstyleoption.h.

Enumerations

◆ CheckType

This enum is used to indicate whether or not a check mark should be drawn for the item, or even if it should be drawn at all.

  • NotCheckable The item is not checkable.
  • Exclusive The item is an exclusive check item (like a radio button).
  • NonExclusive The item is a non-exclusive check item (like a check box).
See also
checkType, QAction::checkable, QAction::checked, QActionGroup::exclusive
Enumerator
NotCheckable 
Exclusive 
NonExclusive 

Definition at line 443 of file qstyleoption.h.

◆ MenuItemType

This enum indicates the type of menu item that the structure describes.

  • Normal A normal menu item.
  • DefaultItem A menu item that is the default action as specified with QMenu::defaultAction() .
  • Separator A menu separator.
  • SubMenu Indicates the menu item points to a sub-menu.
  • Scroller A popup menu scroller (currently only used on Mac OS X).
  • TearOff A tear-off handle for the menu.
  • Margin The margin of the menu.
  • EmptyArea The empty area of the menu.
See also
menuItemType
Enumerator
Normal 
DefaultItem 
Separator 
SubMenu 
Scroller 
TearOff 
Margin 
EmptyArea 

Definition at line 441 of file qstyleoption.h.

◆ StyleOptionType

This enum is used to hold information about the type of the style option, and is defined for each QStyleOption subclass.

  • Type The type of style option provided (SO_MenuItem for this class).

The type is used internally by QStyleOption, its subclasses, and qstyleoption_cast() to determine the type of style option. In general you do not need to worry about this unless you want to create your own QStyleOption subclass and your own styles.

See also
StyleOptionVersion
Enumerator
Type 

Definition at line 438 of file qstyleoption.h.

◆ StyleOptionVersion

This enum is used to hold information about the version of the style option, and is defined for each QStyleOption subclass.

  • Version 1

The version is used by QStyleOption subclasses to implement extensions without breaking compatibility. If you use qstyleoption_cast(), you normally do not need to check it.

See also
StyleOptionType
Enumerator
Version 

Definition at line 439 of file qstyleoption.h.

Constructors and Destructors

◆ QStyleOptionMenuItem() [1/3]

QStyleOptionMenuItem::QStyleOptionMenuItem ( )

Constructs a QStyleOptionMenuItem, initializing the members variables to their default values.

Definition at line 2993 of file qstyleoption.cpp.

2996 {
2997 }
int maxIconWidth
the maximum icon width for the icon in the menu item
Definition: qstyleoption.h:452
bool checked
whether the menu item is checked or not
Definition: qstyleoption.h:447
bool menuHasCheckableItems
whether the menu as a whole has checkable items or not
Definition: qstyleoption.h:448
MenuItemType menuItemType
the type of menu item
Definition: qstyleoption.h:445
QStyleOption(int version=QStyleOption::Version, int type=SO_Default)
Constructs a QStyleOption with the specified version and type.
int tabWidth
the tab width for the menu item
Definition: qstyleoption.h:453
CheckType checkType
the type of checkmark of the menu item
Definition: qstyleoption.h:446

◆ QStyleOptionMenuItem() [2/3]

QStyleOptionMenuItem::QStyleOptionMenuItem ( const QStyleOptionMenuItem other)
inline

Constructs a copy of the other style option.

Definition at line 457 of file qstyleoption.h.

457 : QStyleOption(Version, Type) { *this = other; }
QStyleOption(int version=QStyleOption::Version, int type=SO_Default)
Constructs a QStyleOption with the specified version and type.

◆ QStyleOptionMenuItem() [3/3]

QStyleOptionMenuItem::QStyleOptionMenuItem ( int  version)
protected
Warning
This function is not part of the public interface.

Definition at line 3002 of file qstyleoption.cpp.

3005 {
3006 }
int version
the version of the style option
Definition: qstyleoption.h:86
int maxIconWidth
the maximum icon width for the icon in the menu item
Definition: qstyleoption.h:452
bool checked
whether the menu item is checked or not
Definition: qstyleoption.h:447
bool menuHasCheckableItems
whether the menu as a whole has checkable items or not
Definition: qstyleoption.h:448
MenuItemType menuItemType
the type of menu item
Definition: qstyleoption.h:445
QStyleOption(int version=QStyleOption::Version, int type=SO_Default)
Constructs a QStyleOption with the specified version and type.
int tabWidth
the tab width for the menu item
Definition: qstyleoption.h:453
CheckType checkType
the type of checkmark of the menu item
Definition: qstyleoption.h:446

Properties

◆ checked

QStyleOptionMenuItem::checked

whether the menu item is checked or not

The default value is false.

Definition at line 447 of file qstyleoption.h.

Referenced by QStyleSheetStyle::drawControl(), QComboMenuDelegate::getStyleOption(), and QMenu::initStyleOption().

◆ checkType

QStyleOptionMenuItem::checkType

◆ font

QStyleOptionMenuItem::font

the font used for the menu item text

This is the font that should be used for drawing the menu text minus the shortcut. The shortcut is usually drawn using the painter's font. By default, the application's default font is used.

Definition at line 454 of file qstyleoption.h.

Referenced by QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QGtkStyle::drawControl(), QComboMenuDelegate::getStyleOption(), and QMenu::initStyleOption().

◆ icon

QStyleOptionMenuItem::icon

the icon for the menu item

The default value is an empty icon, i.e. an icon with neither a pixmap nor a filename.

Definition at line 451 of file qstyleoption.h.

Referenced by QStyleSheetStyle::drawControl(), QComboMenuDelegate::getStyleOption(), QMenuBar::initStyleOption(), and QMenu::initStyleOption().

◆ maxIconWidth

QStyleOptionMenuItem::maxIconWidth

the maximum icon width for the icon in the menu item

This can be used for drawing the icon into the correct place or properly aligning items. The variable must be set regardless of whether or not the menu item has an icon. The default value is 0.

Definition at line 452 of file qstyleoption.h.

Referenced by QPlastiqueStyle::drawControl(), QStyleSheetStyle::drawControl(), QComboMenuDelegate::getStyleOption(), QMenu::initStyleOption(), QComboBoxListView::paintEvent(), QMenu::paintEvent(), and QComboBoxPrivateScroller::paintEvent().

◆ menuHasCheckableItems

QStyleOptionMenuItem::menuHasCheckableItems

whether the menu as a whole has checkable items or not

The default value is true.

If this option is set to false, then the menu has no checkable items. This makes it possible for GUI styles to save some horizontal space that would normally be used for the check column.

Definition at line 448 of file qstyleoption.h.

Referenced by QMenu::initStyleOption().

◆ menuItemType

QStyleOptionMenuItem::menuItemType

◆ menuRect

QStyleOptionMenuItem::menuRect

the rectangle for the entire menu

The default value is a null rectangle, i.e. a rectangle with both the width and the height set to 0.

Definition at line 449 of file qstyleoption.h.

Referenced by QComboMenuDelegate::getStyleOption(), QMenuBar::heightForWidth(), QMenuBar::initStyleOption(), QMenu::initStyleOption(), QMenuBar::minimumSizeHint(), QComboBoxListView::paintEvent(), QMenuBar::paintEvent(), QMenu::paintEvent(), QComboBoxPrivateScroller::paintEvent(), and QMenuBar::sizeHint().

◆ tabWidth

QStyleOptionMenuItem::tabWidth

the tab width for the menu item

The tab width is the distance between the text of the menu item and the shortcut. The default value is 0.

Definition at line 453 of file qstyleoption.h.

Referenced by QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QGtkStyle::drawControl(), QStyleSheetStyle::drawControl(), QComboMenuDelegate::getStyleOption(), QMenu::initStyleOption(), QComboBoxListView::paintEvent(), QMenu::paintEvent(), and QComboBoxPrivateScroller::paintEvent().

◆ text

QStyleOptionMenuItem::text

the text for the menu item

Note that the text format is something like this "Menu text<b>\\t</b>Shortcut".

If the menu item doesn't have a shortcut, it will just contain the menu item's text. The default value is an empty string.

Definition at line 450 of file qstyleoption.h.

Referenced by QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QGtkStyle::drawControl(), QStyleSheetStyle::drawControl(), QComboMenuDelegate::getStyleOption(), QMenuBar::initStyleOption(), and QMenu::initStyleOption().


The documentation for this class was generated from the following files: