本文整理汇总了C++中QAction::setParent方法的典型用法代码示例。如果您正苦于以下问题:C++ QAction::setParent方法的具体用法?C++ QAction::setParent怎么用?C++ QAction::setParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAction
的用法示例。
在下文中一共展示了QAction::setParent方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: menuSessionsAboutToShow
void MainWindow::menuSessionsAboutToShow()
{
if (m_sessionsGroup)
{
m_sessionsGroup->deleteLater();
QAction *saveSessionAction = m_ui->menuSessions->actions().at(0);
saveSessionAction->setParent(this);
QAction *manageSessionsAction = m_ui->menuSessions->actions().at(1);
manageSessionsAction->setParent(this);
m_ui->menuSessions->clear();
m_ui->menuSessions->addAction(saveSessionAction);
m_ui->menuSessions->addAction(manageSessionsAction);
m_ui->menuSessions->addSeparator();
}
m_sessionsGroup = new QActionGroup(this);
m_sessionsGroup->setExclusive(true);
const QStringList sessions = SessionsManager::getSessions();
QMultiHash<QString, SessionInformation> information;
for (int i = 0; i < sessions.count(); ++i)
{
const SessionInformation session = SessionsManager::getSession(sessions.at(i));
information.insert((session.title.isEmpty() ? tr("(Untitled)") : session.title), session);
}
const QList<SessionInformation> sorted = information.values();
const QString currentSession = SessionsManager::getCurrentSession();
for (int i = 0; i < sorted.count(); ++i)
{
int windows = 0;
for (int j = 0; j < sorted.at(i).windows.count(); ++j)
{
windows += sorted.at(i).windows.at(j).windows.count();
}
QAction *action = m_ui->menuSessions->addAction(tr("%1 (%n tab(s))", "", windows).arg(sorted.at(i).title.isEmpty() ? tr("(Untitled)") : QString(sorted.at(i).title).replace(QLatin1Char('&'), QLatin1String("&&"))));
action->setData(sorted.at(i).path);
action->setCheckable(true);
action->setChecked(sorted.at(i).path == currentSession);
m_sessionsGroup->addAction(action);
}
}
示例2: updateTeardownAction
void KUrlNavigatorPlacesSelector::updateTeardownAction()
{
const int rowCount = m_placesModel->rowCount();
if (m_placesMenu->actions().size() == rowCount + 2) {
// remove teardown action
QAction *action = m_placesMenu->actions().at(rowCount + 1);
m_placesMenu->removeAction(action);
delete action;
// remove separator
action = m_placesMenu->actions().at(rowCount);
m_placesMenu->removeAction(action);
delete action;
}
const QModelIndex index = m_placesModel->index(m_selectedItem, 0);
QAction *teardown = m_placesModel->teardownActionForIndex(index);
if (teardown != 0) {
teardown->setParent(m_placesMenu);
teardown->setData("teardownAction");
m_placesMenu->addSeparator();
m_placesMenu->addAction(teardown);
}
}
示例3: getToolbars
void QCastViewGL::getToolbars(CPtrVector<QToolBar>& toolbars)
{
if (! pView) return;
CPtrVector<cogx::display::CDisplayCamera> cameras;
pView->getCameras(cameras);
if (cameras.size() < 1) return;
// pBar->parent will be reset in QViewContainer
QToolBar *pBar = new QToolBar(QString::fromStdString(pView->m_id), this);
if (pBar) {
unsigned int nc = cameras.size();
if (nc > 3) nc = 3;
cogx::display::CDisplayCamera* pCamera;
for (unsigned int i= 0; i < nc; i++) {
QToolButton *pBut = new QToolButton(pBar);
pCamera = cameras[i];
QString text = QString::fromStdString(pCamera->name);
QAction* pAct = new QAction(QIcon(":/toolButton/camera-photo.png"), text, pBut);
pAct->setToolTip("Select Camera: " + text);
pAct->setData(qVariantFromValue((void*)pCamera));
pBut->setDefaultAction(pAct);
pBar->addWidget(pBut);
pBar->connect(pAct, SIGNAL(triggered()), this, SLOT(onCameraChangeAction()));
// With more than 3 cameras things become complicated...
if (i == 2 && cameras.size() > 2) {
QAction *pPopAct;
QMenu *pMenu = new QMenu(pBut); // parent MUST be button, see onCameraChangeAction
pBut->setMenu(pMenu);
pBut->setPopupMode(QToolButton::MenuButtonPopup);
for (unsigned int j = 0; j < cameras.size(); j++) {
if (i == j) {
pMenu->addAction(pAct);
pAct->setParent(pMenu); // parent MUST be menu, see onCameraChangeAction
}
else {
pCamera = cameras[j];
text = QString::fromStdString(pCamera->name);
pPopAct = pMenu->addAction(QIcon(":/toolButton/camera-photo.png"), text);
pPopAct->setData(qVariantFromValue((void*)pCamera));
pPopAct->setToolTip("Select Camera: " + text);
pBar->connect(pPopAct, SIGNAL(triggered()), this, SLOT(onCameraChangeAction()));
}
}
if (0) {
text = "TODO: Configure camera buttons...";
pPopAct = pMenu->addAction(QIcon(":/toolButton/camera-photo.png"), text);
pBar->connect(pPopAct, SIGNAL(triggered()), this, SLOT(onActConfigureCameras()));
}
}
}
toolbars.push_back(pBar);
}
}
示例4: qWarning
Command *ActionManagerPrivate::registerOverridableAction(QAction *action, const QString &id, bool checkUnique)
{
OverrideableAction *a = 0;
const int uid = UniqueIDManager::instance()->uniqueIdentifier(id);
if (CommandPrivate * c = m_idCmdMap.value(uid, 0)) {
a = qobject_cast<OverrideableAction *>(c);
if (!a) {
qWarning() << "registerAction: id" << id << "is registered with a different command type.";
return c;
}
} else {
a = new OverrideableAction(uid);
m_idCmdMap.insert(uid, a);
}
if (!a->action()) {
QAction *baseAction = new QAction(m_mainWnd);
baseAction->setObjectName(id);
baseAction->setCheckable(action->isCheckable());
baseAction->setIcon(action->icon());
baseAction->setIconText(action->iconText());
baseAction->setText(action->text());
baseAction->setToolTip(action->toolTip());
baseAction->setStatusTip(action->statusTip());
baseAction->setWhatsThis(action->whatsThis());
baseAction->setChecked(action->isChecked());
baseAction->setSeparator(action->isSeparator());
baseAction->setShortcutContext(Qt::ApplicationShortcut);
baseAction->setEnabled(false);
baseAction->setParent(m_mainWnd);
#ifdef Q_WS_MAC
baseAction->setIconVisibleInMenu(false);
#endif
a->setAction(baseAction);
m_mainWnd->addAction(baseAction);
a->setKeySequence(a->keySequence());
a->setDefaultKeySequence(QKeySequence());
} else if (checkUnique) {
qWarning() << "registerOverridableAction: id" << id << "is already registered.";
}
return a;
}
示例5: contextMenuEvent
void ImageViewer::contextMenuEvent(QContextMenuEvent *event) {
if (!m_flipbook) return;
QAction *action;
if (m_isColorModel) {
event->ignore();
return;
}
QMenu *menu = new QMenu(this);
if (m_flipbook->getPreviewedFx()) {
if (!(windowState() & Qt::WindowFullScreen)) {
action = menu->addAction(tr("Clone Preview"));
action->setShortcut(QKeySequence(
CommandManager::instance()->getKeyFromId(MI_ClonePreview)));
connect(action, SIGNAL(triggered()), m_flipbook, SLOT(clonePreview()));
}
if (m_flipbook->isFreezed()) {
action = menu->addAction(tr("Unfreeze Preview"));
action->setShortcut(QKeySequence(
CommandManager::instance()->getKeyFromId(MI_FreezePreview)));
connect(action, SIGNAL(triggered()), m_flipbook, SLOT(unfreezePreview()));
} else {
action = menu->addAction(tr("Freeze Preview"));
action->setShortcut(QKeySequence(
CommandManager::instance()->getKeyFromId(MI_FreezePreview)));
connect(action, SIGNAL(triggered()), m_flipbook, SLOT(freezePreview()));
}
action = menu->addAction(tr("Regenerate Preview"));
action->setShortcut(QKeySequence(
CommandManager::instance()->getKeyFromId(MI_RegeneratePreview)));
connect(action, SIGNAL(triggered()), m_flipbook, SLOT(regenerate()));
action = menu->addAction(tr("Regenerate Frame Preview"));
action->setShortcut(QKeySequence(
CommandManager::instance()->getKeyFromId(MI_RegenerateFramePr)));
connect(action, SIGNAL(triggered()), m_flipbook, SLOT(regenerateFrame()));
menu->addSeparator();
}
action = menu->addAction(tr("Load / Append Images"));
connect(action, SIGNAL(triggered()), m_flipbook, SLOT(loadImages()));
// history of the loaded paths of flipbook
action = CommandManager::instance()->getAction(MI_LoadRecentImage);
menu->addAction(action);
action->setParent(m_flipbook);
if (m_flipbook->isSavable()) {
action = menu->addAction(tr("Save Images"));
connect(action, SIGNAL(triggered()), m_flipbook, SLOT(saveImages()));
}
menu->addSeparator();
QAction *reset = menu->addAction(tr("Reset View"));
reset->setShortcut(
QKeySequence(CommandManager::instance()->getKeyFromId(V_ZoomReset)));
connect(reset, SIGNAL(triggered()), SLOT(resetView()));
QAction *fit = menu->addAction(tr("Fit To Window"));
fit->setShortcut(
QKeySequence(CommandManager::instance()->getKeyFromId(V_ZoomFit)));
connect(fit, SIGNAL(triggered()), SLOT(fitView()));
#ifdef _WIN32
if (ImageUtils::FullScreenWidget *fsWidget =
dynamic_cast<ImageUtils::FullScreenWidget *>(parentWidget())) {
bool isFullScreen = (fsWidget->windowState() & Qt::WindowFullScreen) != 0;
action = menu->addAction(isFullScreen ? tr("Exit Full Screen Mode")
: tr("Full Screen Mode"));
action->setShortcut(QKeySequence(
CommandManager::instance()->getKeyFromId(V_ShowHideFullScreen)));
connect(action, SIGNAL(triggered()), fsWidget, SLOT(toggleFullScreen()));
}
#endif
bool addedSep = false;
if (m_isHistogramEnable &&
visibleRegion().contains(event->pos() * getDevPixRatio())) {
menu->addSeparator();
addedSep = true;
action = menu->addAction(tr("Show Histogram"));
connect(action, SIGNAL(triggered()), SLOT(showHistogram()));
}
if (m_visualSettings.m_doCompare) {
if (!addedSep) menu->addSeparator();
action = menu->addAction(tr("Swap Compared Images"));
connect(action, SIGNAL(triggered()), SLOT(swapCompared()));
}
//.........这里部分代码省略.........
示例6: slotItemContextMenuRequested
void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
{
PlacesItem* item = m_model->placesItem(index);
if (!item) {
return;
}
QMenu menu(this);
QAction* emptyTrashAction = nullptr;
QAction* editAction = nullptr;
QAction* teardownAction = nullptr;
QAction* ejectAction = nullptr;
const QString label = item->text();
const bool isDevice = !item->udi().isEmpty();
const bool isTrash = (item->url().scheme() == QLatin1String("trash"));
if (isDevice) {
ejectAction = m_model->ejectAction(index);
if (ejectAction) {
ejectAction->setParent(&menu);
menu.addAction(ejectAction);
}
teardownAction = m_model->teardownAction(index);
if (teardownAction) {
teardownAction->setParent(&menu);
menu.addAction(teardownAction);
}
if (teardownAction || ejectAction) {
menu.addSeparator();
}
} else {
if (isTrash) {
emptyTrashAction = menu.addAction(QIcon::fromTheme(QStringLiteral("trash-empty")), i18nc("@action:inmenu", "Empty Trash"));
emptyTrashAction->setEnabled(item->icon() == QLatin1String("user-trash-full"));
menu.addSeparator();
}
}
QAction* openInNewWindowAction = menu.addAction(QIcon::fromTheme("window-new"), i18nc("@item:inmenu", "Open in New Window"));
QAction* openInNewTabAction = menu.addAction(QIcon::fromTheme("tab-new"), i18nc("@item:inmenu", "Open in New Tab"));
if (!isDevice && !isTrash) {
menu.addSeparator();
}
if (!isDevice) {
editAction = menu.addAction(QIcon::fromTheme("document-properties"), i18nc("@item:inmenu", "Edit..."));
}
QAction* removeAction = nullptr;
if (!isDevice && !item->isSystemItem()) {
removeAction = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18nc("@item:inmenu", "Remove"));
}
QAction* hideAction = menu.addAction(i18nc("@item:inmenu", "Hide"));
hideAction->setCheckable(true);
hideAction->setChecked(item->isHidden());
buildGroupContextMenu(&menu, index);
QAction* action = menu.exec(pos.toPoint());
if (action) {
if (action == emptyTrashAction) {
emptyTrash();
} else {
// The index might have changed if devices were added/removed while
// the context menu was open.
index = m_model->index(item);
if (index < 0) {
// The item is not in the model any more, probably because it was an
// external device that has been removed while the context menu was open.
return;
}
if (action == editAction) {
editEntry(index);
} else if (action == removeAction) {
m_model->deleteItem(index);
} else if (action == hideAction) {
item->setHidden(hideAction->isChecked());
} else if (action == openInNewWindowAction) {
Dolphin::openNewWindow({KFilePlacesModel::convertedUrl(m_model->data(index).value("url").toUrl())}, this);
} else if (action == openInNewTabAction) {
// TriggerItem does set up the storage first and then it will
// emit the slotItemMiddleClicked signal, because of Qt::MiddleButton.
triggerItem(index, Qt::MiddleButton);
} else if (action == teardownAction) {
m_model->requestTearDown(index);
} else if (action == ejectAction) {
m_model->requestEject(index);
}
}
}
selectClosestItem();
}
示例7: slotItemContextMenuRequested
void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
{
PlacesItem* item = m_model->placesItem(index);
if (!item) {
return;
}
QMenu menu(this);
QAction* emptyTrashAction = 0;
QAction* addAction = 0;
QAction* mainSeparator = 0;
QAction* editAction = 0;
QAction* teardownAction = 0;
QAction* ejectAction = 0;
const QString label = item->text();
const bool isDevice = !item->udi().isEmpty();
if (isDevice) {
ejectAction = m_model->ejectAction(index);
if (ejectAction) {
ejectAction->setParent(&menu);
menu.addAction(ejectAction);
}
teardownAction = m_model->teardownAction(index);
if (teardownAction) {
teardownAction->setParent(&menu);
menu.addAction(teardownAction);
}
if (teardownAction || ejectAction) {
mainSeparator = menu.addSeparator();
}
} else {
if (item->url() == QUrl(QStringLiteral("trash:/"))) {
emptyTrashAction = menu.addAction(QIcon::fromTheme(QStringLiteral("trash-empty")), i18nc("@action:inmenu", "Empty Trash"));
emptyTrashAction->setEnabled(item->icon() == QLatin1String("user-trash-full"));
menu.addSeparator();
}
addAction = menu.addAction(QIcon::fromTheme(QStringLiteral("document-new")), i18nc("@item:inmenu", "Add Entry..."));
mainSeparator = menu.addSeparator();
editAction = menu.addAction(QIcon::fromTheme(QStringLiteral("document-properties")), i18nc("@item:inmenu", "Edit '%1'...", label));
}
if (!addAction) {
addAction = menu.addAction(QIcon::fromTheme(QStringLiteral("document-new")), i18nc("@item:inmenu", "Add Entry..."));
}
QAction* openInNewTabAction = menu.addAction(i18nc("@item:inmenu", "Open '%1' in New Tab", label));
openInNewTabAction->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
QAction* removeAction = 0;
if (!isDevice && !item->isSystemItem()) {
removeAction = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18nc("@item:inmenu", "Remove '%1'", label));
}
QAction* hideAction = menu.addAction(i18nc("@item:inmenu", "Hide '%1'", label));
hideAction->setCheckable(true);
hideAction->setChecked(item->isHidden());
QAction* showAllAction = 0;
if (m_model->hiddenCount() > 0) {
if (!mainSeparator) {
mainSeparator = menu.addSeparator();
}
showAllAction = menu.addAction(i18nc("@item:inmenu", "Show All Entries"));
showAllAction->setCheckable(true);
showAllAction->setChecked(m_model->hiddenItemsShown());
}
menu.addSeparator();
QMenu* iconSizeSubMenu = new QMenu(i18nc("@item:inmenu", "Icon Size"), &menu);
struct IconSizeInfo
{
int size;
const char* context;
const char* text;
};
const int iconSizeCount = 4;
static const IconSizeInfo iconSizes[iconSizeCount] = {
{KIconLoader::SizeSmall, I18N_NOOP2_NOSTRIP("Small icon size", "Small (%1x%2)")},
{KIconLoader::SizeSmallMedium, I18N_NOOP2_NOSTRIP("Medium icon size", "Medium (%1x%2)")},
{KIconLoader::SizeMedium, I18N_NOOP2_NOSTRIP("Large icon size", "Large (%1x%2)")},
{KIconLoader::SizeLarge, I18N_NOOP2_NOSTRIP("Huge icon size", "Huge (%1x%2)")}
};
QHash<QAction*, int> iconSizeActionMap;
QActionGroup* iconSizeGroup = new QActionGroup(iconSizeSubMenu);
for (int i = 0; i < iconSizeCount; ++i) {
const int size = iconSizes[i].size;
const QString text = i18nc(iconSizes[i].context, iconSizes[i].text,
size, size);
QAction* action = iconSizeSubMenu->addAction(text);
iconSizeActionMap.insert(action, size);
//.........这里部分代码省略.........
示例8: strItem
QWidget *QFRDRTableDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const {
QVariant dat=index.data(Qt::DisplayRole);
QString expression=index.data(QFRDRTable::TableExpressionRole).toString();
if (expression.isEmpty()) {
if (dat.type()==QVariant::Invalid) {
dat=index.data(Qt::EditRole);
}
if ( dat.type() == QVariant::DateTime || dat.type() == QVariant::Time || dat.type() == QVariant::Date ) {
QDateTimeEdit *editor = new QDateTimeEdit(parent);
//editor->setDisplayFormat("dd/M/yyyy");
editor->setCalendarPopup(true);
return editor;
}
if ( !index.isValid() || dat.type() == QVariant::Double ) {
QFDoubleEdit* editor=new QFDoubleEdit(parent);
editor->setCheckBounds(false, false);
editor->setShowUpDown(false);
return editor;
}
if ( dat.type() == QVariant::Int || dat.type() == QVariant::LongLong ) {
QSpinBox* editor=new QSpinBox(parent);
editor->setRange(INT_MIN, INT_MAX);
editor->setButtonSymbols(QAbstractSpinBox::NoButtons);
return editor;
}
if ( dat.type() == QVariant::UInt || dat.type() == QVariant::ULongLong ) {
QSpinBox* editor=new QSpinBox(parent);
editor->setRange(0, UINT_MAX);
editor->setButtonSymbols(QAbstractSpinBox::NoButtons);
return editor;
}
if ( dat.type() == QVariant::Bool) {
QCheckBox* editor=new QCheckBox(parent);
return editor;
}
QLineEdit *editor = new QLineEdit(parent);
// create a completer with the strings in the column as model
QStringList allStrings;
for (int i = 1; i<index.model()->rowCount(); i++) {
QString strItem(index.model()->data(index.sibling(i, index.column()),
Qt::EditRole).toString());
if (!allStrings.contains(strItem))
allStrings.append(strItem);
}
QCompleter *autoComplete = new QCompleter(allStrings);
editor->setCompleter(autoComplete);
connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
return editor;
} else {
QWidget* widExpression=new QWidget(parent);
widExpression->setFocusPolicy(Qt::StrongFocus);
widExpression->setAutoFillBackground(true);
QHBoxLayout* layout=new QHBoxLayout();
layout->setContentsMargins(0,0,0,0);
layout->setSpacing(1);
widExpression->setLayout(layout);
QLabel* label=new QLabel(widExpression);
layout->addWidget(label, 1);
label->setTextFormat(Qt::RichText);
label->setText(tr("<b><font color=\"blue\">Σ:</font> %1</b><i> = %2</i>").arg(expression).arg(dat.toString()));
label->setAutoFillBackground(true);
QFont f=label->font();
f.setPointSizeF(f.pointSizeF()*0.9);
label->setFont(f);
QAction* actEdtExp;
QToolButton* btnEdtExp=createButtonAndAction(actEdtExp, QIcon(":/table/formula.png"), tr("edit expression ..."), widExpression);
actEdtExp->setParent(widExpression);
connect(actEdtExp, SIGNAL(triggered()), this, SLOT(doEditExpression()));
layout->addWidget(btnEdtExp);
QAction* actClearExp;
QToolButton* btnClearExp=createButtonAndAction(actClearExp, QIcon(":/table/formulaclear.png"), tr("clear expression ..."), widExpression);
actClearExp->setParent(widExpression);
connect(actClearExp, SIGNAL(triggered()), this, SLOT(doClearExpression()));
layout->addWidget(btnClearExp);
widExpression->setFocus();
return widExpression;
}
}