Qt5之菜单

本文介绍了如何在Qt5中创建菜单,并通过QAction绑定槽函数,实现点击菜单触发相应功能。当菜单被触发时,会发出triggered()信号。此外,还讨论了如何使用QSS文件来定制菜单的外观,包括设置图标和字体样式。
摘要由CSDN通过智能技术生成

1、创建

 // 创建 打开 、设置、 退出菜单
    topMenuActionStart[0]   = new QAction(tr("Open(&o)"));
    // 添加提示
    topMenuActionStart[0]->setToolTip(tr("open a file"));
    // 设置菜单前的ico图标
    topMenuActionStart[0]->setIcon(QIcon(":/res/ico/menu/open"));

    topMenuActionStart[1]   = new QAction(tr("Setting(&s)"));
    topMenuActionStart[1]->setToolTip(tr("can get most data"));
    topMenuActionStart[1]->setIcon(QIcon(":/res/ico/menu/setting"));

    topMenuActionStart[2]   = new QAction(tr("Exit(&e)"));
    topMenuActionStart[2]->setToolTip(tr("exit the app"));
    topMenuActionStart[2]->setIcon(QIcon(":/res/ico/menu/exit"));

2、绑定槽函数

点击菜单,会触发 triggered() 信号

connect(topMenuActionStart[0], SIGNAL(triggered()), this, SLOT(TopMenuStartSlotOpen()));

Qt文档原文:

[signal] void QAction::triggered(bool checked = false)
This signal is emitted when an action is activated by the user; for example, when the user clicks a menu option, toolbar button, or presses an action's shortcut key combination, or when trigger() was called. Notably, it is not emitted when setChecked() or toggle() is called.
If the action is checkable, checked is true if the action is checked, or false if the action is unchecked.
See also QAction::activate(), QAction::toggled(), and checked. 

3、效果


 可以用QSS文件设置控件属性,设置图标,设置字体等。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值