本文整理汇总了C++中QDialogButtonBox::buttonRole方法的典型用法代码示例。如果您正苦于以下问题:C++ QDialogButtonBox::buttonRole方法的具体用法?C++ QDialogButtonBox::buttonRole怎么用?C++ QDialogButtonBox::buttonRole使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDialogButtonBox
的用法示例。
在下文中一共展示了QDialogButtonBox::buttonRole方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: confirm
/*!
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());
}
示例2: CustomMessageBox
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());
}
示例3: keyPressEvent
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);
}
}
示例4: msgBox
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());
}
示例5: tabChanged
/**
* @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);
}
}
}
}
示例6: done
/*!
\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);
}
示例7: keyPressEvent
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);
}
}
示例8: dialogButtonsAction
void LxQtPanelPluginConfigDialog::dialogButtonsAction(QAbstractButton *btn)
{
QDialogButtonBox *box = qobject_cast<QDialogButtonBox*>(btn->parent());
if (box && box->buttonRole(btn) == QDialogButtonBox::ResetRole)
{
mOldSettings.loadToSettings();
loadSettings();
}
else
{
close();
}
}
示例9: buttonClicked
void ChordsManager::buttonClicked(QAbstractButton *button){
QDialogButtonBox* buttonBox = (QDialogButtonBox*)sender();
if(buttonBox->buttonRole(button)==QDialogButtonBox::ResetRole){
qDebug() << "Restore";
}
}
示例10: setStandardKeys
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
//.........这里部分代码省略.........