QStyleOptionMenuItem 類

QStyleOptionMenuItem 類是用於繪製菜單項的必要描述參數。 更多...

頭: #include <QStyleOptionMenuItem>
qmake: QT += widgets
繼承: QStyleOption

公共類型

enum CheckType { NotCheckable, Exclusive, NonExclusive }
enum MenuItemType { Normal, DefaultItem, Separator, SubMenu, Scroller, …, EmptyArea }
enum StyleOptionType { Type }
enum StyleOptionVersion { Version }

公共函數

QStyleOptionMenuItem (const QStyleOptionMenuItem & other )
QStyleOptionMenuItem ()

公共變量

QStyleOptionMenuItem::CheckType checkType
bool checked
QFont font
QIcon icon
int maxIconWidth
bool menuHasCheckableItems
QStyleOptionMenuItem::MenuItemType menuItemType
QRect menuRect
int tabWidth
QString text

詳細描述

QStyleOptionMenuItem 包含所有信息當 QStyle 函數需要繪製菜單項從 QMenu 。它還用於繪製其它相關菜單 Widget。

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.

對於可以如何使用樣式選項的演示範例,見 樣式 範例。

另請參閱 QStyleOption .

成員類型文檔編製

enum QStyleOptionMenuItem:: CheckType

此枚舉用於指示是否應該為項繪製復選標記,或者即使根本不應該繪製復選標記。

常量 描述
QStyleOptionMenuItem::NotCheckable 0 項不可復選。
QStyleOptionMenuItem::Exclusive 1 項是獨占復選項 (像:單選按鈕)。
QStyleOptionMenuItem::NonExclusive 2 項是非獨占復選項 (像:復選框)。

另請參閱 checkType , QAction::checkable , QAction::checked ,和 QActionGroup::exclusionPolicy .

此枚舉指示結構描述的菜單項類型。

常量 描述
QStyleOptionMenuItem::Normal 0 正常菜單項。
QStyleOptionMenuItem::DefaultItem 1 菜單項是默認動作如指定采用 QMenu::defaultAction ().
QStyleOptionMenuItem::Separator 2 菜單分隔符。
QStyleOptionMenuItem::SubMenu 3 指示菜單項指嚮子菜單。
QStyleOptionMenuItem::Scroller 4 彈齣菜單滾動條 (目前僅用於 macOS)。
QStyleOptionMenuItem::TearOff 5 菜單的撕離手柄。
QStyleOptionMenuItem::Margin 6 菜單的邊距。
QStyleOptionMenuItem::EmptyArea 7 菜單的空區域。

另請參閱 menuItemType .

enum QStyleOptionMenuItem:: StyleOptionType

This enum is used to hold information about the type of the style option, and is defined for each QStyleOption 子類。

常量 描述
QStyleOptionMenuItem::Type SO_MenuItem 提供樣式選項的類型 ( SO_MenuItem 對於此類)。

類型內部使用通過 QStyleOption ,其子類,和 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.

另請參閱 StyleOptionVersion .

enum QStyleOptionMenuItem:: StyleOptionVersion

This enum is used to hold information about the version of the style option, and is defined for each QStyleOption 子類。

常量 描述
QStyleOptionMenuItem::Version 1 1

版本的使用通過 QStyleOption 子類以實現擴展在不破壞兼容性的情況下。若使用 qstyleoption_cast (),通常不需要校驗它。

另請參閱 StyleOptionType .

成員函數文檔編製

QStyleOptionMenuItem:: QStyleOptionMenuItem (const QStyleOptionMenuItem & other )

構造副本為 other 樣式選項。

QStyleOptionMenuItem:: QStyleOptionMenuItem ()

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

成員變量文檔編製

QStyleOptionMenuItem::CheckType QStyleOptionMenuItem:: checkType

This variable holds the type of checkmark of the menu item

默認值為 NotCheckable .

另請參閱 CheckType .

bool QStyleOptionMenuItem:: checked

This variable holds whether the menu item is checked or not

默認值為 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

默認值為空圖標 (即:圖標既沒有像素圖,也沒有文件名)。

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.

This variable holds whether the menu as a whole has checkable items or not

默認值為 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.

This variable holds the type of menu item

默認值為 Normal .

另請參閱 MenuItemType .

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

int QStyleOptionMenuItem:: tabWidth

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.

默認值為 0。

QString QStyleOptionMenuItem:: text

This variable holds the text for the menu item

Note that the text format is something like this "Menu text \t 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.