QToolButton弹出菜单

QToolButton弹出菜单

 1 QToolButton *toolButton= new QToolButton;
 2 QMenu *menu = new QMenu();
 3 menu->addMenu(tr("菜单1"));
 4 menu->addMenu(tr("菜单2"));
 5 menu->addMenu(tr("菜单3"));
 6 toolButton->setIcon(QPixmap("images//menupic.png"));
 7 toolButton->setIconSize(QPixmap( "images//menupic.png").size());
 8 toolButton->setToolButtonStyle( Qt::ToolButtonTextUnderIcon);
 9 toolButton->setPopupMode(QToolButton::InstantPopup );
10 toolButton->setMenu(menu);

弹出菜单的弹出方式有3种:

Constant Value Description
QToolButton::DelayedPopup 0 After pressing and holding the tool button down for a certain amount of time (the timeout is style dependent, see QStyle::SH_ToolButton_PopupDelay), the menu is displayed. A typical application example is the "back" button in some web browsers's tool bars. If the user clicks it, the browser simply browses back to the previous page. If the user presses and holds the button down for a while, the tool button shows a menu containing the current history list
QToolButton::MenuButtonPopup 1 In this mode the tool button displays a special arrow to indicate that a menu is present. The menu is displayed when the arrow part of the button is pressed.
QToolButton::InstantPopup 2 The menu is displayed, without delay, when the tool button is pressed. In this mode, the button's own action is not triggered.

 

posted on 2021-08-16 14:02  Cynthia_W  阅读(915)  评论(0编辑  收藏  举报