您的位置:首页 > 编程语言 > Qt开发

QToolButton设置弹出菜单

2009-01-15 17:03 169 查看
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, 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::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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐