如何设置QMenu上Icon的大小,无论加载的图标
展开全部
.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();
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询