本文整理汇总了C++中QAction::data方法的典型用法代码示例。如果您正苦于以下问题:C++ QAction::data方法的具体用法?C++ QAction::data怎么用?C++ QAction::data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAction
的用法示例。
在下文中一共展示了QAction::data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: slotHeaderContextMenu
void ItemsTreeView::slotHeaderContextMenu(const QPoint &point)
{
const int section = header()->logicalIndexAt(point);
QMenu menu;
for (int i = 0; i < header()->count(); ++i) {
const QString title = model()->headerData(i, Qt::Horizontal).toString();
QAction *showHideAction = new QAction(title, &menu);
showHideAction->setCheckable(true);
showHideAction->setChecked(!header()->isSectionHidden(i));
showHideAction->setData(i);
menu.addAction(showHideAction);
}
const ItemsTreeModel::ColumnType columnType = mItemsTreeModel->columnTypes().at(section);
switch (columnType) {
case ItemsTreeModel::NextStepDate:
case ItemsTreeModel::CreationDate:
case ItemsTreeModel::LastModifiedDate:
qDebug() << "Clicked on a date!";
default:
break;
}
QAction *selectedAction = menu.exec(header()->mapToGlobal(point));
if (selectedAction) {
const QVariant var = selectedAction->data();
if (var.type() == QVariant::Int) {
const int toggleSection = var.toInt();
const bool hide = !selectedAction->isChecked();
header()->setSectionHidden(toggleSection, hide);
saveHeaderView();
}
}
}
示例2: tapMenu
void TlevelCreatorDlg::tapMenu() {
TtouchMenu *menu = new TtouchMenu(this);
if (m_levelSett->saveButton()->isEnabled()) {
QAction *saveAct = actionFromButton(m_levelSett->saveButton(), menu);
saveAct->setData(10);
menu->addAction(saveAct);
}
if (m_levelSett->startExerciseButton()->isEnabled()) {
QAction *exerciseAct = actionFromButton(m_levelSett->startExerciseButton(), menu);
exerciseAct->setData(11);
menu->addAction(exerciseAct);
}
if (m_levelSett->startExamButton()->isEnabled()) {
QAction *examAct = actionFromButton(m_levelSett->startExamButton(), menu);
examAct->setData(12);
menu->addAction(examAct);
}
for (int i = 0; i < buttonBox->buttons().size(); ++i) {
QAction *buttonAction = new QAction(buttonBox->buttons()[i]->icon(), buttonBox->buttons()[i]->text(), menu);
buttonAction->setData((i));
menu->addAction(buttonAction);
}
QAction *menuAction = menu->exec(QPoint(navList->width(), height() -menu->sizeHint().height()), QPoint(navList->width(), height()));
int actionNumber = menuAction ? menuAction->data().toInt() : -1;
delete menu; // delete menu before performing its action
if (actionNumber != -1) { // no action
if (actionNumber < 10) // button box actions
buttonBox->buttons()[actionNumber]->click();
else if (actionNumber == 10)
m_levelSett->saveButton()->click();
else if (actionNumber == 11)
m_levelSett->startExerciseButton()->click();
else if (actionNumber == 12)
m_levelSett->startExamButton()->click();
}
}
示例3: moveRight
void BookmarksToolbar::moveRight()
{
QAction* act = qobject_cast<QAction*> (sender());
if (!act) {
return;
}
ToolButton* button = (ToolButton*) act->data().value<void*>();
int index = m_layout->indexOf(button);
if (index == m_layout->count() - 1) {
return;
}
ToolButton* buttonRight = qobject_cast<ToolButton*> (m_layout->itemAt(index + 1)->widget());
if (!buttonRight || buttonRight->menu()) {
return;
}
Bookmark bookmark = button->data().value<Bookmark>();
Bookmark bookmarkRight = buttonRight->data().value<Bookmark>();
QSqlQuery query;
query.prepare("UPDATE bookmarks SET toolbar_position=? WHERE id=?");
query.addBindValue(index + 1);
query.addBindValue(bookmark.id);
mApp->dbWriter()->executeQuery(query);
query.prepare("UPDATE bookmarks SET toolbar_position=? WHERE id=?");
query.addBindValue(index);
query.addBindValue(bookmarkRight.id);
mApp->dbWriter()->executeQuery(query);
QWidget* w = m_layout->takeAt(index)->widget();
m_layout->insertWidget(index + 1, w);
}
示例4: fillLanguages
void MainWindow::fillLanguages()
{
// make a group of language actions
QActionGroup* actionsDir = new QActionGroup(this);
QActionGroup* actionsRes = new QActionGroup(this);
QSettings settings;
QString locale = QLocale::system().name().left(2);
QString lang = settings.value("Language", locale).toString();
if (!Application::availableLanguagesRes().contains(lang))
lang = "en";
bool langSet = false;
this->ui->menu_Pomoc->addSeparator();
connect(actionsRes, SIGNAL(triggered(QAction*)), this, SLOT(setLanguageRes(QAction*)));
connect(actionsDir, SIGNAL(triggered(QAction*)), this, SLOT(setLanguageDir(QAction*)));
foreach (QString avail, Application::availableLanguagesRes())
{
// figure out nice names for locales
QLocale locale(avail);
QString name = QLocale::languageToString(locale.language());
// construct an action
QAction* action = this->ui->menu_Pomoc->addAction(name);
action->setData(avail);
action->setCheckable(true);
actionsRes->addAction(action);
if (action->data().toString() == lang)
{
langSet = true;
action->setChecked(true);
Application::setLanguage(lang, "res");
}
}
示例5: main
//.........这里部分代码省略.........
// graphics
if (menGraph->actions().count() > 0) {
menMain->addMenu(menGraph);
}
// ham radio
if (menHam->actions().count() > 0) {
menMain->addMenu(menHam);
}
// internet/networking
if (menInter->actions().count() > 0) {
menMain->addMenu(menInter);
}
// multimedia / sound/video
if (menMulti->actions().count() > 0) {
menMain->addMenu(menMulti);
}
// office
if (menOffic->actions().count() > 0) {
menMain->addMenu(menOffic);
}
// other
if (menOth->actions().count() > 0) {
menMain->addMenu(menOth);
}
// science
if (menSci->actions().count() > 0) {
menMain->addMenu(menSci);
}
// system
if (menSys->actions().count() > 0) {
menMain->addMenu(menSys);
}
menMain->addSeparator();
qaAction = new QAction("About...", NULL);
qaAction->setData("...about...");
qaAction->setIcon(QIcon::fromTheme("dialog-information"));
menMain->addAction(qaAction);
menMain->addSeparator();
qaAction = new QAction("Run...", NULL);
qaAction->setData(strRunCommand);
menMain->addAction(qaAction);
menMain->addSeparator();
qaAction = new QAction("Exit", NULL);
qaAction->setData(strExitCommand);
qaAction->setIcon(QIcon::fromTheme("system-log-out"));
menMain->addAction(qaAction);
qaAction = new QAction("Reboot", NULL);
qaAction->setData(strRebootCommand);
qaAction->setIcon(QIcon::fromTheme("view-refresh"));
menMain->addAction(qaAction);
qaAction = new QAction("Shutdown", NULL);
qaAction->setData(strPoweroffCommand);
qaAction->setIcon(QIcon::fromTheme("system-shutdown"));
menMain->addAction(qaAction);
// set correct positioning
if (nLeft == -1) {
nLeft = qrDesktop.left();
}
if (nTop == -1) {
nTop = qrDesktop.bottom();
}
// show menu
qaAction = menMain->exec(QPoint(nLeft, nTop));
// perform/run selected action
if (qaAction != 0) {
QString qsExec = qaAction->data().toString();
if (qsExec == "...about...") {
QMessageBox::about(NULL,
"About Qt Menu - Standalone",
"<h3>Qt Menu - Standalone</h3><br><br>"
"Copyright 2014 - Will Brokenbourgh<br>"
"Blog: http://www.pismotek.com/brainout/<br><br>"
"Version 0.1.1");
} else {
QProcess *qp = new QProcess();
qp->setWorkingDirectory(QDir::homePath());
qp->start(qsExec);
}
}
}
示例6: openRecentFile
// Opens a log file from the recent files list
void MainWindow::openRecentFile()
{
QAction* action = qobject_cast<QAction*>(sender());
if (action)
loadFile(action->data().toString());
}
示例7: save
void MainWindow::save()
{
QAction *action = qobject_cast<QAction *>(sender());
QByteArray fileFormat = action->data().toByteArray();
saveFile(fileFormat);
}
示例8: menu_op
void CodChangeMsgDialog::menu_op()
{
QMenu m(0);
MenuFactory::addItem(m, tr("Choose"), -1);
m.addSeparator();
int index = list.indexOf(edoper->currentText().trimmed());
if (index != -1)
MenuFactory::addItem(m, tr("Select in browser"), 0);
BrowserNode * bn = BrowserView::selected_item();
if ((bn != 0) &&
(bn->get_type() == UmlOperation) &&
!bn->deletedp() &&
(opers.indexOf((OperationData *) bn->get_data()) != -1))
MenuFactory::addItem(m, tr("Choose operation selected in browser"), 1);
else
bn = 0;
if (cl != 0)
MenuFactory::addItem(m, tr("Create operation and choose it"), 2);
if ((index != -1) || (bn != 0) || (cl != 0)) {
QAction* retAction = m.exec(QCursor::pos());
if(retAction)
{
switch (retAction->data().toInt()) {
case 0:
opers[index]->get_browser_node()->select_in_browser();
break;
case 2:
bn = cl->add_operation();
if (bn == 0)
return;
bn->select_in_browser();
// no break
case 1: {
OperationData * od = (OperationData *) bn->get_data();
if ((index = opers.indexOf(od)) == -1) {
index = opers.count();
opers.append(od);
QString s = od->definition(TRUE, FALSE);
list.append(s);
edoper->addItem(s);
}
}
edoper->setCurrentIndex(index + 1);
}
}
}
}
示例9: openRecentFile
void RecentFiles::openRecentFile()
{
QAction *action = qobject_cast<QAction *>(sender());
if (action)
emit openFile(action->data().toString());
}
示例10: setForceField
void MainWindow::setForceField()
{
QAction* action = qobject_cast<QAction*>(sender());
if (action) m_viewerModel.setForceField(action->data().toString());
}
示例11: menu_type
void ParameterDialog::menu_type()
{
QMenu m(0);
MenuFactory::addItem(m, tr("Choose"), -1);
m.addSeparator();
int index = list.indexOf(edtype->currentText().trimmed());
if (index != -1)
MenuFactory::addItem(m, tr("Select in browser"), 0);
BrowserNode * bn = 0;
if (! visit) {
bn = BrowserView::selected_item();
if ((bn != 0) && (bn->get_type() == UmlClass) && !bn->deletedp())
MenuFactory::addItem(m, tr("Choose class selected in browser"), 1);
else
bn = 0;
MenuFactory::addItem(m, tr("Create class and choose it"), 2);
}
if (!visit || (index != -1) || (bn != 0)) {
QAction* retAction = m.exec(QCursor::pos());
if(retAction)
{
switch (retAction->data().toInt()) {
case 0:
nodes.at(index)->select_in_browser();
break;
case 2:
bn = BrowserClass::add_class(FALSE, view);
if (bn == 0)
return;
bn->select_in_browser();
// no break
case 1: {
QString s = bn->full_name(TRUE);
if ((index = list.indexOf(s)) == -1) {
// new class, may be created through an other dialog
index = 0;
QStringList::Iterator iter = list.begin();
QStringList::Iterator iter_end = list.end();
while ((iter != iter_end) && (*iter < s)) {
++iter;
index += 1;
}
nodes.insert((unsigned) index, bn);
list.insert(iter, s);
edtype->insertItem(index + offset,s);
}
}
edtype->setCurrentIndex(index + offset);
break;
default:
break;
}
}
}
}
示例12: openRecentFile
void NodeEditorWindows::openRecentFile()
{
QAction *action = qobject_cast<QAction *>(sender());
if (action)
_project->openProject(action->data().toString());
}
示例13: moveRowDown
void TableWidget::moveRowDown(){
QAction *action = qobject_cast<QAction *>(sender());
ColumnType t = (ColumnType)action->data().toInt();
int current = currentRow();
moveRow( current, current+1, t );
}
示例14: setStickMode
void JoyControlStickContextMenu::setStickMode()
{
QAction *action = static_cast<QAction*>(sender());
int item = action->data().toInt();
stick->setJoyMode((JoyControlStick::JoyMode)item);
}
示例15: setStickPreset
void JoyControlStickContextMenu::setStickPreset()
{
PadderCommon::lockInputDevices();
InputDevice *tempDevice = stick->getParentSet()->getInputDevice();
QMetaObject::invokeMethod(tempDevice, "haltServices", Qt::BlockingQueuedConnection);
QAction *action = static_cast<QAction*>(sender());
int item = action->data().toInt();
JoyButtonSlot *upButtonSlot = 0;
JoyButtonSlot *downButtonSlot = 0;
JoyButtonSlot *leftButtonSlot = 0;
JoyButtonSlot *rightButtonSlot = 0;
JoyButtonSlot *upLeftButtonSlot = 0;
JoyButtonSlot *upRightButtonSlot = 0;
JoyButtonSlot *downLeftButtonSlot = 0;
JoyButtonSlot *downRightButtonSlot = 0;
if (item == 0)
{
upButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this);
downButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this);
leftButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this);
rightButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this);
stick->setJoyMode(JoyControlStick::StandardMode);
stick->setDiagonalRange(65);
}
else if (item == 1)
{
upButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this);
downButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this);
leftButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this);
rightButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this);
stick->setJoyMode(JoyControlStick::StandardMode);
stick->setDiagonalRange(65);
}
else if (item == 2)
{
upButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this);
downButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this);
leftButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this);
rightButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this);
stick->setJoyMode(JoyControlStick::StandardMode);
stick->setDiagonalRange(65);
}
else if (item == 3)
{
upButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this);
downButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this);
leftButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this);
rightButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this);
stick->setJoyMode(JoyControlStick::StandardMode);
stick->setDiagonalRange(65);
}
else if (item == 4)
{
upButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Up), Qt::Key_Up, JoyButtonSlot::JoyKeyboard, this);
downButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Down), Qt::Key_Down, JoyButtonSlot::JoyKeyboard, this);
leftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Left), Qt::Key_Left, JoyButtonSlot::JoyKeyboard, this);
rightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Right), Qt::Key_Right, JoyButtonSlot::JoyKeyboard, this);
stick->setJoyMode(JoyControlStick::StandardMode);
stick->setDiagonalRange(45);
}
else if (item == 5)
{
upButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_W), Qt::Key_W, JoyButtonSlot::JoyKeyboard, this);
downButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_S), Qt::Key_S, JoyButtonSlot::JoyKeyboard, this);
leftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_A), Qt::Key_A, JoyButtonSlot::JoyKeyboard, this);
rightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_D), Qt::Key_D, JoyButtonSlot::JoyKeyboard, this);
stick->setJoyMode(JoyControlStick::StandardMode);
stick->setDiagonalRange(45);
}
else if (item == 6)
{
if (stick->getJoyMode() == JoyControlStick::StandardMode ||
stick->getJoyMode() == JoyControlStick::FourWayCardinal)
{
upButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_8), QtKeyMapperBase::AntKey_KP_8, JoyButtonSlot::JoyKeyboard, this);
downButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_2), QtKeyMapperBase::AntKey_KP_2, JoyButtonSlot::JoyKeyboard, this);
leftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_4), QtKeyMapperBase::AntKey_KP_4, JoyButtonSlot::JoyKeyboard, this);
rightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_6), QtKeyMapperBase::AntKey_KP_6, JoyButtonSlot::JoyKeyboard, this);
}
else if (stick->getJoyMode() == JoyControlStick::EightWayMode)
{
upButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_8), QtKeyMapperBase::AntKey_KP_8, JoyButtonSlot::JoyKeyboard, this);
downButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_2), QtKeyMapperBase::AntKey_KP_2, JoyButtonSlot::JoyKeyboard, this);
leftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_4), QtKeyMapperBase::AntKey_KP_4, JoyButtonSlot::JoyKeyboard, this);
rightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_6), QtKeyMapperBase::AntKey_KP_6, JoyButtonSlot::JoyKeyboard, this);
upLeftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_7), QtKeyMapperBase::AntKey_KP_7, JoyButtonSlot::JoyKeyboard, this);
upRightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_9), QtKeyMapperBase::AntKey_KP_9, JoyButtonSlot::JoyKeyboard, this);
downLeftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_1), QtKeyMapperBase::AntKey_KP_1, JoyButtonSlot::JoyKeyboard, this);
downRightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_3), QtKeyMapperBase::AntKey_KP_3, JoyButtonSlot::JoyKeyboard, this);
}
else if (stick->getJoyMode() == JoyControlStick::FourWayDiagonal)
{
upLeftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_7), QtKeyMapperBase::AntKey_KP_7, JoyButtonSlot::JoyKeyboard, this);
upRightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_9), QtKeyMapperBase::AntKey_KP_9, JoyButtonSlot::JoyKeyboard, this);
downLeftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_1), QtKeyMapperBase::AntKey_KP_1, JoyButtonSlot::JoyKeyboard, this);
//.........这里部分代码省略.........