本文整理汇总了C++中IAction::icon方法的典型用法代码示例。如果您正苦于以下问题:C++ IAction::icon方法的具体用法?C++ IAction::icon怎么用?C++ IAction::icon使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAction
的用法示例。
在下文中一共展示了IAction::icon方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getSharedQAction
QSharedPointer<QAction> QtMenu::createSharedQAction(IAction& action)
{
auto qAction = getSharedQAction(action);
if (qAction)
{
return qAction;
}
qAction.reset(new QForwardingAction(action.text(), QApplication::instance()), &QObject::deleteLater);
sharedQActions_[&action] = qAction;
qAction->setProperty("order", action.order());
qAction->setEnabled(action.enabled());
qAction->setVisible(action.visible());
if (action.isSeparator())
{
qAction->setSeparator(true);
}
else
{
std::vector<QIcon> qIcons;
auto icons = StringUtils::split(std::string(action.icon()), '|');
for(auto& icon : icons)
{
StringUtils::trim_string(icon);
qIcons.push_back(QtMenu_Locals::generateIcon(icon.c_str()));
}
if(!qIcons.empty())
{
qAction->setIcon(qIcons[0]);
}
qAction->setShortcut(QKeySequence(action.shortcut()));
if (action.isCheckable())
{
qAction->setCheckable(true);
qAction->setChecked(action.checked());
}
QObject::connect(qAction.data(), &QAction::triggered, [&action]() {
if (!action.enabled())
{
return;
}
action.execute();
});
connections_[&action] = action.signalShortcutChanged.connect([qAction](const char* shortcut) {
TF_ASSERT(qAction != nullptr);
qAction->setShortcut(QKeySequence(shortcut));
});
connections_[&action] = action.signalTextChanged.connect([qAction](const char* text) {
TF_ASSERT(qAction != nullptr);
qAction->setText(text);
});
connections_[&action] = action.signalVisibilityChanged.connect([qAction](bool visible) {
TF_ASSERT(qAction != nullptr);
qAction->setVisible(visible);
});
connections_[&action] = action.signalIconChanged.connect([qAction, qIcons](int index) {
TF_ASSERT(qAction != nullptr);
if(index >= 0 && index < (int)qIcons.size())
{
qAction->setIcon(qIcons[index]);
}
});
const std::string groupID(action.group());
if (!groupID.empty())
{
auto itr = groups_.find(groupID);
if (itr == groups_.end())
{
groups_[groupID].reset(new QActionGroup(&menu_));
}
groups_.at(groupID)->addAction(qAction.data());
TF_ASSERT(qAction->actionGroup());
}
}
return qAction;
}