如何设置QMenu上Icon的大小,无论加载的图标
1个回答
展开全部
.h 文件
protected slots:
void onMenuTriggered(QAction*);12
.cpp 文件
// 菜单
QMenu *pMenu = new QMenu(this);
pMenu->addAction(QString::fromLocal8Bit("我"));
pMenu->addSeparator();
pMenu->addAction(QString::fromLocal8Bit("爱"));
QMenu *pChildMenu = new QMenu(this);
pChildMenu->setTitle(QStringLiteral("学"));
pChildMenu->addAction(QStringLiteral("Q"));
pMenu->addMenu(pChildMenu);
QAction *act1 = new QAction(pChildMenu);
act1->setText(QStringLiteral("t"));
act1->setIcon(QIcon("src/Me.png"));
pChildMenu->addAction(act1);
QPushButton *pButton = new QPushButton(this);
// 按钮
pButton->setText(QString::fromLocal8Bit("主菜单"));
// 设置菜单
pButton->setMenu(pMenu);
connect(pMenu, SIGNAL(triggered(QAction*)), this, SLOT(onMenuTriggered(QAction*)));123456789101112131415161718192021222324
void MyClass::onMenuTriggered(QAction *action)
{
QString str = action->text();
}
protected slots:
void onMenuTriggered(QAction*);12
.cpp 文件
// 菜单
QMenu *pMenu = new QMenu(this);
pMenu->addAction(QString::fromLocal8Bit("我"));
pMenu->addSeparator();
pMenu->addAction(QString::fromLocal8Bit("爱"));
QMenu *pChildMenu = new QMenu(this);
pChildMenu->setTitle(QStringLiteral("学"));
pChildMenu->addAction(QStringLiteral("Q"));
pMenu->addMenu(pChildMenu);
QAction *act1 = new QAction(pChildMenu);
act1->setText(QStringLiteral("t"));
act1->setIcon(QIcon("src/Me.png"));
pChildMenu->addAction(act1);
QPushButton *pButton = new QPushButton(this);
// 按钮
pButton->setText(QString::fromLocal8Bit("主菜单"));
// 设置菜单
pButton->setMenu(pMenu);
connect(pMenu, SIGNAL(triggered(QAction*)), this, SLOT(onMenuTriggered(QAction*)));123456789101112131415161718192021222324
void MyClass::onMenuTriggered(QAction *action)
{
QString str = action->text();
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
博思aippt
2024-07-20 广告
2024-07-20 广告
博思AIPPT是基于ai制作PPT的智能在线工具,它提供了4种AI制作PPT的方式,包括AI生成大纲、AI直接生成PPT、文本生成PPT、AI提炼文档生成PPT,一站式集成多种AI生成PPT的方式,可满足办公用户的不同需求和使用场景。ai生...
点击进入详情页
本回答由博思aippt提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询