/*! Opens an confirmation message box with the specified \a title, \a text and \a confirmation. The standard \a buttons are added to the message box. \a defaultButton specifies the button used when Enter is pressed. \a defaultButton must refer to a button that was given in \a buttons. If \a defaultButton is QMessageBox::NoButton, QMessageBox chooses a suitable default automatically. Returns the identity of the standard button that was clicked. If Esc was pressed instead, the escape button is returned. If \a parent is \c 0, the message box is an application modal dialog box. If \a parent is a widget, the message box is window modal relative to \a parent. */ QMessageBox::StandardButton QxtConfirmationMessage::confirm(QWidget* parent, const QString& title, const QString& text, const QString& confirmation, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) { QxtConfirmationMessage msgBox(QMessageBox::NoIcon, title, text, confirmation, QMessageBox::NoButton, parent); QDialogButtonBox* buttonBox = qFindChild<QDialogButtonBox*>(&msgBox); Q_ASSERT(buttonBox != 0); uint mask = QMessageBox::FirstButton; while (mask <= QMessageBox::LastButton) { uint sb = buttons & mask; mask <<= 1; if (!sb) continue; QPushButton* button = msgBox.addButton((QMessageBox::StandardButton)sb); // Choose the first accept role as the default if (msgBox.defaultButton()) continue; if ((defaultButton == QMessageBox::NoButton && buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) || (defaultButton != QMessageBox::NoButton && sb == uint(defaultButton))) msgBox.setDefaultButton(button); } if (msgBox.exec() == -1) return QMessageBox::Cancel; return msgBox.standardButton(msgBox.clickedButton()); }
int CustomMessageBox(QWidget *parent,QMessageBox::Icon icon,const QString& title,const QString& text,QMessageBox::StandardButtons buttons,QMessageBox::StandardButton defaultButton, QString ButtonYesText,QString ButtonNoText) { Qt::WindowFlags Flags=(Qt::Dialog|Qt::CustomizeWindowHint|Qt::WindowSystemMenuHint|Qt::WindowMaximizeButtonHint)&(~Qt::WindowMinimizeButtonHint); QMessageBox msgBox(icon,title,text,QMessageBox::NoButton,parent,Flags); QDialogButtonBox *buttonBox = msgBox.findChild<QDialogButtonBox*>(); uint mask = QMessageBox::FirstButton; while (mask <= QMessageBox::LastButton) { uint sb = buttons & mask; mask <<= 1; if (!sb) continue; QPushButton *button = msgBox.addButton((QMessageBox::StandardButton)sb); if ((sb==QMessageBox::Yes)&&(!ButtonYesText.isEmpty())) button->setText(ButtonYesText); if ((sb==QMessageBox::No)&&(!ButtonNoText.isEmpty())) button->setText(ButtonNoText); // Choose the first accept role as the default if (msgBox.defaultButton()) continue; if ((defaultButton == QMessageBox::NoButton && buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) || (defaultButton != QMessageBox::NoButton && sb == uint(defaultButton))) msgBox.setDefaultButton(button); } msgBox.setWindowModality(Qt::ApplicationModal); if (msgBox.exec() == -1) return QMessageBox::Cancel; return msgBox.standardButton(msgBox.clickedButton()); }
void TaskView::keyPressEvent(QKeyEvent* ke) { if (ActiveCtrl && ActiveDialog) { if (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter) { // get all buttons of the complete task dialog QList<QPushButton*> list = this->findChildren<QPushButton*>(); for (int i=0; i<list.size(); ++i) { QPushButton *pb = list.at(i); if (pb->isDefault() && pb->isVisible()) { if (pb->isEnabled()) pb->click(); return; } } } else if (ke->key() == Qt::Key_Escape) { // get only the buttons of the button box QDialogButtonBox* box = ActiveCtrl->standardButtons(); QList<QAbstractButton*> list = box->buttons(); for (int i=0; i<list.size(); ++i) { QAbstractButton *pb = list.at(i); if (box->buttonRole(pb) == QDialogButtonBox::RejectRole) { if (pb->isEnabled()) pb->click(); return; } } } } else { QScrollArea::keyPressEvent(ke); } }
static QMessageBox::StandardButton showNewMessageBox(QWidget *parent, QMessageBox::Icon icon, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) { QMessageBox msgBox(icon, title, text, QMessageBox::NoButton, parent); QDialogButtonBox *buttonBox = msgBox.findChild<QDialogButtonBox *>(); Q_ASSERT(buttonBox != 0); uint mask = QMessageBox::FirstButton; while (mask <= QMessageBox::LastButton) { uint sb = buttons & mask; mask <<= 1; if (!sb) continue; QPushButton *button = msgBox.addButton((QMessageBox::StandardButton)sb); // Choose the first accept role as the default if (msgBox.defaultButton()) continue; if ((defaultButton == QMessageBox::NoButton && buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) || (defaultButton != QMessageBox::NoButton && sb == uint(defaultButton))) { msgBox.setDefaultButton(button); } } #if defined(Q_OS_OSX) msgBox.setWindowModality(Qt::WindowModal); #endif if (msgBox.exec() == -1) return QMessageBox::Cancel; return msgBox.standardButton(msgBox.clickedButton()); }
/** * @brief the current tab changed */ void OpenNIC::tabChanged(int tab) { QDialogButtonBox* buttonBox = ui->buttonBox; QList<QAbstractButton *> buttons = buttonBox->buttons(); for(int n=0; n < buttons.count(); n++) { QAbstractButton* button = buttons.at(n); if (buttonBox->buttonRole(button) == QDialogButtonBox::ApplyRole || buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) { if ( tab == 1 || tab == 5 ) { button->setEnabled(true); } else { button->setEnabled(false); } } } }
/*! \reimp */ void QxtConfirmationMessage::done(int result) { QDialogButtonBox* buttons = qFindChild<QDialogButtonBox*>(this); Q_ASSERT(buttons != 0); int role = buttons->buttonRole(clickedButton()); if (qxt_d().confirm->isChecked() && (qxt_d().remember || role != QDialogButtonBox::RejectRole)) { qxt_d().doNotShowAgain(result); } QMessageBox::done(result); }
void TaskView::keyPressEvent(QKeyEvent* ke) { if (ActiveCtrl && ActiveDialog) { if (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter) { // get all buttons of the complete task dialog QList<QPushButton*> list = this->findChildren<QPushButton*>(); for (int i=0; i<list.size(); ++i) { QPushButton *pb = list.at(i); if (pb->isDefault() && pb->isVisible()) { if (pb->isEnabled()) { #if defined(FC_OS_MACOSX) // #0001354: Crash on using Enter-Key for confirmation of chamfer or fillet entries QPoint pos = QCursor::pos(); QCursor::setPos(pb->parentWidget()->mapToGlobal(pb->pos())); #endif pb->click(); #if defined(FC_OS_MACOSX) QCursor::setPos(pos); #endif } return; } } } else if (ke->key() == Qt::Key_Escape) { // get only the buttons of the button box QDialogButtonBox* box = ActiveCtrl->standardButtons(); QList<QAbstractButton*> list = box->buttons(); for (int i=0; i<list.size(); ++i) { QAbstractButton *pb = list.at(i); if (box->buttonRole(pb) == QDialogButtonBox::RejectRole) { if (pb->isEnabled()) { #if defined(FC_OS_MACOSX) // #0001354: Crash on using Enter-Key for confirmation of chamfer or fillet entries QPoint pos = QCursor::pos(); QCursor::setPos(pb->parentWidget()->mapToGlobal(pb->pos())); #endif pb->click(); #if defined(FC_OS_MACOSX) QCursor::setPos(pos); #endif } return; } } } } else { QScrollArea::keyPressEvent(ke); } }
void LxQtPanelPluginConfigDialog::dialogButtonsAction(QAbstractButton *btn) { QDialogButtonBox *box = qobject_cast<QDialogButtonBox*>(btn->parent()); if (box && box->buttonRole(btn) == QDialogButtonBox::ResetRole) { mOldSettings.loadToSettings(); loadSettings(); } else { close(); } }
void ChordsManager::buttonClicked(QAbstractButton *button){ QDialogButtonBox* buttonBox = (QDialogButtonBox*)sender(); if(buttonBox->buttonRole(button)==QDialogButtonBox::ResetRole){ qDebug() << "Restore"; } }
void shortcuts::setStandardKeys(QWidget* widget) { if (!widget) return; // Add standard shortcuts to applicable buttons bool hasShortcut = false; QPushButton* button; // For Save button = widget->findChild<QPushButton*>("_save"); if (button) { button->setShortcut(QKeySequence::Save); button->setToolTip(button->text().remove("&") + " " + button->shortcut().toString(QKeySequence::NativeText)); hasShortcut = true; } if (!hasShortcut) // Because some screens have both { // For Post button = widget->findChild<QPushButton*>("_post"); if (button) { button->setShortcut(QKeySequence::Save); button->setToolTip(button->text().remove("&") + " " + button->shortcut().toString(QKeySequence::NativeText)); } } if (!hasShortcut) { QDialogButtonBox* bb = widget->findChild<QDialogButtonBox*>(); if (bb) { QList<QAbstractButton*> buttons = bb->buttons(); for (int i = 0; i < buttons.size(); ++i) { QAbstractButton *bbutton = buttons.at(i); QDialogButtonBox::ButtonRole btnrole = bb->buttonRole(buttons.at(i)); if (btnrole == QDialogButtonBox::AcceptRole) { bbutton->setShortcut(QKeySequence::Save); bbutton->setToolTip(bbutton->text().remove("&") + " " + bbutton->shortcut().toString(QKeySequence::NativeText)); } else if (btnrole == QDialogButtonBox::RejectRole) { bbutton->setShortcut(QKeySequence::Close); bbutton->setToolTip(bbutton->text().remove("&") + " " + bbutton->shortcut().toString(QKeySequence::NativeText)); } } } } // For Close hasShortcut = false; button = widget->findChild<QPushButton*>("_close"); if (button) { button->setShortcut(QKeySequence::Close); button->setToolTip(button->text().remove("&") + " " + button->shortcut().toString(QKeySequence::NativeText)); hasShortcut = true; } if (!hasShortcut) // Because some screens have both { // For Post button = widget->findChild<QPushButton*>("_cancel"); if (button) { button->setShortcut(QKeySequence::Close); button->setToolTip(button->text().remove("&") + " " + button->shortcut().toString(QKeySequence::NativeText)); } } // For New button = widget->findChild<QPushButton*>("_new"); if (button) { button->setShortcut(QKeySequence::New); button->setToolTip(button->text().remove("&") + " " + button->shortcut().toString(QKeySequence::NativeText)); hasShortcut = true; } // For Print button = widget->findChild<QPushButton*>("_print"); if (button) { button->setShortcut(QKeySequence::Print); button->setToolTip(button->text().remove("&") + " " + button->shortcut().toString(QKeySequence::NativeText)); hasShortcut = true; } // For Query button = widget->findChild<QPushButton*>("_query"); if (button) { button->setShortcut(QKeySequence::Refresh); button->setToolTip(button->text().remove("&") + " " + button->shortcut().toString(QKeySequence::NativeText)); hasShortcut = true; } // Page up/down for tab widgets QTabWidget* tab = widget->findChild<QTabWidget*>(); if (tab) { TabWidgetNavigtor* tabNav = new TabWidgetNavigtor(tab, widget); QAction* pagedownAct = new QAction(tab); pagedownAct->setShortcut(QKeySequence::MoveToNextPage); pagedownAct->connect(pagedownAct, SIGNAL(triggered()), tabNav, SLOT(pageDown())); tab->addAction(pagedownAct); QAction* pageupAct = new QAction(tab); pageupAct->setShortcut(QKeySequence::MoveToPreviousPage); pageupAct->connect(pageupAct, SIGNAL(triggered()), tabNav, SLOT(pageUp())); tab->addAction(pageupAct); } }