• 大小: 7KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-14
  • 语言: 其他
  • 标签: QPushButton  菜单  

资源简介

QPushButton下拉式二级菜单.zip

资源截图

代码片段和文件信息

#include “buttonmenu.h“
#include 

ButtonMenu::ButtonMenu(QWidget *parent)
: QWidget(parent)
{
m_menu = new QMenu(this);
m_addAction = new QAction(m_menu);
m_subAction = new QAction(m_menu);
m_delAction = new QAction(m_menu);
m_addAction->setCheckable(true);//是否可以check
m_delAction->setCheckable(true);//是否可以check
m_addAction->setText(Qobject::tr(“添加“));
m_subAction->setText(Qobject::tr(“子菜单“));
m_delAction->setText(Qobject::tr(“删除“));
m_menu->addAction(m_addAction);
m_menu->addAction(m_delAction);
m_menu->addAction(m_subAction);
connect(m_addAction &QAction::triggered this &ButtonMenu::addFunc);
connect(m_delAction &QAction::triggered this &ButtonMenu::delFunc);

m_subMenu = new QMenu(this);
m_subAdd = new QAction(m_subMenu);
m_subDel = new QAction(m_subMenu);
m_subAdd->setText(Qobject::tr(“子添加“));
m_subDel->setText(Qobject::tr(“子删除“));
m_subMenu->addAction(m_subAdd);
m_subMenu->addAction(m_subDel);
m_subAction->setMenu(m_subMenu);

m_pushButton = new QPushButton(this);
m_pushButton->setText(Qobject::tr(“测试按钮菜单“));
m_pushButton->setMenu(m_menu);//设置菜单

//m_pushButton->setstyleSheet(“QPushButton::menu-indicator{image:none;}“);//不显示下拉图片
}

ButtonMenu::~ButtonMenu()
{

}

void ButtonMenu::addFunc()
{
qDebug() << “addFunc“;
}

void ButtonMenu::delFunc()
{
qDebug() << “delFunc“;
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-04-22 12:12  ButtonMenu\
     文件        1426  2016-04-22 12:03  ButtonMenu\buttonmenu.cpp
     文件         576  2016-04-22 12:04  ButtonMenu\buttonmenu.h
     文件          70  2016-04-22 10:46  ButtonMenu\buttonmenu.qrc
     文件       16346  2016-04-22 10:55  ButtonMenu\ButtonMenu.vcxproj
     文件        2454  2016-04-22 10:55  ButtonMenu\ButtonMenu.vcxproj.filters
     文件         629  2016-04-22 10:55  ButtonMenu\ButtonMenu.vcxproj.user
     目录           0  2016-04-22 10:55  ButtonMenu\GeneratedFiles\
     目录           0  2016-04-22 10:55  ButtonMenu\GeneratedFiles\Debug\
     文件        2706  2016-04-22 12:02  ButtonMenu\GeneratedFiles\Debug\moc_buttonmenu.cpp
     文件        1414  2016-04-22 11:57  ButtonMenu\GeneratedFiles\qrc_buttonmenu.cpp
     目录           0  2016-04-22 10:46  ButtonMenu\GeneratedFiles\Release\
     文件         179  2016-04-22 10:46  ButtonMenu\main.cpp
     目录           0  2016-04-22 10:46  ButtonMenu\Resources\

评论

共有 条评论