QToolButton设置弹出菜单

转自:http://blog.csdn.net/ny13524/article/details/3790112

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.

ConstantValueDescription
QToolButton::DelayedPopup0After pressing and holding the tool button down for a certain amount of time (the timeout is style dependant, seeQStyle::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::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.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值