IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QStyleOptionMenuItem Class

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

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QStyleOptionMenuItem Class

  • Header: QStyleOptionMenuItem

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Widgets)

    target_link_libraries(mytarget PRIVATE Qt6::Widgets)

  • qmake: QT += widgets

  • Inherits: QStyleOption

Detailed Description

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, there are few member functions and the access to the member variables is direct (i.e., using the . or -> operator). This 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 Styles example.

See Also

See also QStyleOption

Member Type Documentation

 

enum QStyleOptionMenuItem::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.

Constant

Value

Description

QStyleOptionMenuItem::NotCheckable

0

The item is not checkable.

QStyleOptionMenuItem::Exclusive

1

The item is an exclusive check item (like a radio button).

QStyleOptionMenuItem::NonExclusive

2

The item is a non-exclusive check item (like a check box).

See Also

enum QStyleOptionMenuItem::MenuItemType

Constant

Value

Description

QStyleOptionMenuItem::Normal

0

A normal menu item.

QStyleOptionMenuItem::DefaultItem

1

A menu item that is the default action as specified with QMenu::defaultAction().

QStyleOptionMenuItem::Separator

2

A menu separator.

QStyleOptionMenuItem::SubMenu

3

Indicates the menu item points to a sub-menu.

QStyleOptionMenuItem::Scroller

4

A popup menu scroller (currently only used on macOS).

QStyleOptionMenuItem::TearOff

5

A tear-off handle for the menu.

QStyleOptionMenuItem::Margin

6

The margin of the menu.

QStyleOptionMenuItem::EmptyArea

7

The empty area of the menu.

See Also

See also menuItemType

enum QStyleOptionMenuItem::StyleOptionType

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

Constant

Value

Description

QStyleOptionMenuItem::Type

SO_MenuItem

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

enum QStyleOptionMenuItem::StyleOptionVersion

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

Constant

Value

Description

QStyleOptionMenuItem::Version

1

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

See also StyleOptionType

Member Function Documentation

 

QStyleOptionMenuItem::QStyleOptionMenuItem()

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

QStyleOptionMenuItem::QStyleOptionMenuItem(const QStyleOptionMenuItem &other)

Constructs a copy of the other style option.

Member Variable Documentation

 

QStyleOptionMenuItem::CheckType QStyleOptionMenuItem::checkType

This variable holds the type of checkmark of the menu item

The default value is NotCheckable.

See Also

See also CheckType

bool QStyleOptionMenuItem::checked

This variable holds whether the menu item is checked or not

The default value is false.

QFont QStyleOptionMenuItem::font

This variable holds 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.

QIcon QStyleOptionMenuItem::icon

This variable holds the icon for the menu item

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

int QStyleOptionMenuItem::maxIconWidth

This variable holds 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.

bool QStyleOptionMenuItem::menuHasCheckableItems

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.

QStyleOptionMenuItem::MenuItemType QStyleOptionMenuItem::menuItemType

The default value is Normal.

See Also

See also MenuItemType

QRect QStyleOptionMenuItem::menuRect

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

int QStyleOptionMenuItem::reservedShortcutWidth

This variable holds the reserved width for the menu item's shortcut

QMenu sets it to the width occupied by the widest shortcut among all visible items within the menu.

The default value is 0.

QString QStyleOptionMenuItem::text

This variable holds the text for the menu item

Note that the text format is something like this "Menu text\tShortcut".

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.

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+