QToolButton设置弹出菜单

来源:互联网 发布:开店在淘宝还是在天猫 编辑:程序博客网 时间:2024/05/16 10:45

QToolButton设置弹出菜单

QToolButton *toolButton= new QToolButton;
QMenu *menu=new QMenu();
menu->addMenu(tr("0"));
menu->addMenu(tr("1"));
menu->addMenu(tr("3"));
toolButton->setIcon( QPixmap( "images//photo1.png" ) );
toolButton->setIconSize( QPixmap( "images//photo1.png").size() );
toolButton->setToolButtonStyle( Qt::ToolButtonTextUnderIcon);
toolButton->setPopupMode(QToolButton::InstantPopup   );
toolButton->setMenu(menu);

弹出菜单的弹出方式有以下几种模式参考(参考Qt4.1.0参考文档):

ToolButtonPopupMode

Describes how a menu should be popped up for tool buttons that has a menu set or contains a list of actions.

ConstantValueDescriptionQToolButton::DelayedPopup0After pressing and holding the tool button down for a certain amount of time (the timeout is style dependant, 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 listQToolButton::MenuButtonPopup1In 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::InstantPopup2The menu is displayed, without delay, when the tool button is pressed. In this mode, the button's own action is not triggered.

 

原创粉丝点击