QT之二级菜单
开场白
今天我们一起来了解下,在我们QT中,二级菜单是如何实现的,在上篇我们学习了QT之系统托盘,QT之自定义菜单, QT之样式styleSheet。今天我们在这基础上,增加二级菜单的功能。
效果图
大家注意下这里箭头,不是用的默认效果哦,还是自定义的好看哈!O(∩_∩)下面这张图示是默认的。
上代码
void SysTray::addSysTrayMenu()
{
CustomMenu* customMenu = new CustomMenu(m_parent);
customMenu->addCustomMenu("onGame", TRAY_ICON, tr("onGame"));
customMenu->addSeparator();
customMenu->addCustomMenu("onShow", TRAY_ICON, tr("onShow"));
customMenu->addSeparator();
customMenu->addCustomMenu("onQuit", CLOSE_MENU, tr("onQuit"));
//子菜单添加和主菜单都是一样流程。
CustomMenu* customSubMenu = new CustomMenu(m_parent);
customSubMenu->addCustomMenu("onBottom", TRAY_ICON_ONDNF, tr("onBottom"));
customSubMenu->addCustomMenu("onMusic", TRAY_ICON_ONMUSIC, tr("onMusic"));
customSubMenu->addCustomMenu("onFire", TRAY_ICON_ONFIRE, tr("onFire"));
customSubMenu->addCustomMenu("onCar", TRAY_ICON_ONCAR, tr("onCar"));
customSubMenu->addCustomMenu("onLol", TRAY_ICON_ONLOL, tr("onLol"));
//关键在这里,为QQ游戏添加子菜单。
customMenu->getAction("onGame")->setMenu(customSubMenu);
connect(customMenu->getAction("onShow"), SIGNAL(triggered(bool)), m_parent, SLOT(onShowNormal()));
connect(customMenu->getAction("onQuit"), SIGNAL(triggered(bool)), m_parent, SLOT(onShowQuit()));
customMenu->exec(QCursor::pos());
delete customMenu;
delete customSubMenu;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
//自定义效果图
QMenu {
border-width:2;
border-image:url(:/Demo/Resources/common_menuborder.png);
}
QMenu::item {
padding: 6px 24px 6px 28px;
}
QMenu::icon {
padding: 0px 0px 0px 9px;
}
QMenu::separator
{
margin-left:24;
margin-right:4;
border-image: url(:/Demo/Resources/menu_separate.png);
}
QMenu::item:selected {
border-image:url(:/Demo/Resources/menu_hover.png);
padding: 6px 24px 6px 28px;
}
QMenu::item:hover {
border-image:url(:/Demo/Resources/menu_hover.png);
padding: 6px 24px 6px 28px;
}
QMenu::right-arrow {
image: url(:/Demo/Resources/common/arrow_up.png);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
可参考文章
下代码
结尾
只为记录,只为分享! 愿所写能对你有所帮助。Good Good Study, Day Day Up!
http://blog.csdn.net/ly305750665/article/details/53769697
时间: 2024-10-13 16:57:09