Qt5之菜单

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文件设置控件属性,设置图标,设置字体等。 

猜你喜欢

转载自blog.csdn.net/hk_5788/article/details/80948251
Qt5