📄 qmessagebox.cpp
字号:
if (!buttonList.contains(d->defaultButton)) d->defaultButton = 0; d->autoAddOkButton = false; d->updateSize();}QMessageBox::StandardButtons QMessageBox::standardButtons() const{ Q_D(const QMessageBox); return QMessageBox::StandardButtons(int(d->buttonBox->standardButtons()));}/*! \since 4.2 Returns the standard button enum value corresponding to the given \a button, or NoButton if the given \a button isn't a standard button. \sa button(), standardButtons()*/QMessageBox::StandardButton QMessageBox::standardButton(QAbstractButton *button) const{ Q_D(const QMessageBox); return (QMessageBox::StandardButton)d->buttonBox->standardButton(button);}/*! \since 4.2 Returns a pointer corresponding to the standard button \a which, or 0 if the standard button doesn't exist in this message box. \sa standardButtons, standardButton()*/QAbstractButton *QMessageBox::button(StandardButton which) const{ Q_D(const QMessageBox); return d->buttonBox->button(QDialogButtonBox::StandardButton(which));}/*! \since 4.2 Returns the button that is activated when escape is pressed. By default, QMessageBox attempts to automatically detect an escape button as follows: \list 1 \o If there is only one button, it is made the escape button. \o If there is a \l Cancel button, it is made the escape button. \o On Mac OS X only, if there is exactly one button with the role QMessageBox::RejectRole, it is made the escape button. \endlist When an escape button could not be automatically detected, pressing \key Esc has no effect. \sa addButton()*/QAbstractButton *QMessageBox::escapeButton() const{ Q_D(const QMessageBox); return d->escapeButton;}/*! \since 4.2 Sets the button that gets activated when the \key Escape key is pressed to \a button. \sa addButton(), clickedButton()*/void QMessageBox::setEscapeButton(QAbstractButton *button){ Q_D(QMessageBox); if (d->buttonBox->buttons().contains(button)) d->escapeButton = button;}/*! \since 4.3 Sets the buttons that gets activated when the \key Escape key is pressed to \a button. \sa addButton(), clickedButton()*/void QMessageBox::setEscapeButton(QMessageBox::StandardButton button){ Q_D(QMessageBox); setEscapeButton(d->buttonBox->button(QDialogButtonBox::StandardButton(button)));}void QMessageBoxPrivate::detectEscapeButton(){ if (escapeButton) { // escape button explicitly set detectedEscapeButton = escapeButton; return; } // Cancel button automatically becomes escape button detectedEscapeButton = buttonBox->button(QDialogButtonBox::Cancel); if (detectedEscapeButton) return; // If there is only one button, make it the escape button const QList<QAbstractButton *> buttons = buttonBox->buttons(); if (buttons.count() == 1) { detectedEscapeButton = buttons.first(); return; }#ifdef Q_WS_MAC // On the Mac, if the message box has one RejectRole button, make it the escape button for (int i = 0; i < buttons.count(); i++) { if (buttonBox->buttonRole(buttons.at(i)) == QDialogButtonBox::RejectRole) { if (detectedEscapeButton) { // already detected! detectedEscapeButton = 0; return; } detectedEscapeButton = buttons.at(i); } }#endif}/*! \since 4.2 Returns the button that was clicked by the user, or 0 if the user hit the \key Esc key and no \l{setEscapeButton()}{escape button} was set. If exec() hasn't been called yet, returns 0. Example: \code QMessageBox messageBox(this); QAbstractButton *disconnectButton = messageBox.addButton(tr("Disconnect"), QMessageBox::ActionRole); ... messageBox.exec(); if (messageBox.clickedButton() == disconnectButton) { ... } \endcode \sa standardButton(), button()*/QAbstractButton *QMessageBox::clickedButton() const{ Q_D(const QMessageBox); return d->clickedButton;}/*! \since 4.2 Returns the button that should be the message box's \l{QPushButton::setDefault()}{default button}. Returns 0 if no default button was set. \sa addButton(), QPushButton::setDefault()*/QPushButton *QMessageBox::defaultButton() const{ Q_D(const QMessageBox); return d->defaultButton;}/*! \since 4.2 Sets the message box's \l{QPushButton::setDefault()}{default button} to \a button. \sa addButton(), QPushButton::setDefault()*/void QMessageBox::setDefaultButton(QPushButton *button){ Q_D(QMessageBox); if (!d->buttonBox->buttons().contains(button)) return; d->defaultButton = button; button->setDefault(true); button->setFocus();}/*! \since 4.3 Sets the message box's \l{QPushButton::setDefault()}{default button} to \a button. \sa addButton(), QPushButton::setDefault()*/void QMessageBox::setDefaultButton(QMessageBox::StandardButton button){ Q_D(QMessageBox); setDefaultButton(d->buttonBox->button(QDialogButtonBox::StandardButton(button)));}/*! \property QMessageBox::text \brief the message box text to be displayed. The text will be interpreted either as a plain text or as rich text, depending on the text format setting (\l QMessageBox::textFormat). The default setting is Qt::AutoText, i.e. the message box will try to auto-detect the format of the text. The default value of this property is an empty string. \sa textFormat*/QString QMessageBox::text() const{ Q_D(const QMessageBox); return d->label->text();}void QMessageBox::setText(const QString &text){ Q_D(QMessageBox); d->label->setText(text); d->label->setWordWrap(d->label->textFormat() == Qt::RichText || (d->label->textFormat() == Qt::AutoText && Qt::mightBeRichText(text))); d->updateSize();}/*! \enum QMessageBox::Icon This enum has the following values: \value NoIcon the message box does not have any icon. \value Question an icon indicating that the message is asking a question. \value Information an icon indicating that the message is nothing out of the ordinary. \value Warning an icon indicating that the message is a warning, but can be dealt with. \value Critical an icon indicating that the message represents a critical problem.*//*! \property QMessageBox::icon \brief the message box's icon The icon of the message box can be one of the following predefined icons: \list \o QMessageBox::NoIcon \o QMessageBox::Question \o QMessageBox::Information \o QMessageBox::Warning \o QMessageBox::Critical \endlist The actual pixmap used for displaying the icon depends on the current \link QWidget::style() GUI style\endlink. You can also set a custom pixmap icon using the \l QMessageBox::iconPixmap property. The default icon is QMessageBox::NoIcon. \sa iconPixmap*/QMessageBox::Icon QMessageBox::icon() const{ Q_D(const QMessageBox); return d->icon;}void QMessageBox::setIcon(Icon icon){ Q_D(QMessageBox); setIconPixmap(QMessageBox::standardIcon((QMessageBox::Icon)icon)); d->icon = icon;}/*! \property QMessageBox::iconPixmap \brief the current icon The icon currently used by the message box. Note that it's often hard to draw one pixmap that looks appropriate in all GUI styles; you may want to supply a different pixmap for each platform. \sa icon*/QPixmap QMessageBox::iconPixmap() const{ Q_D(const QMessageBox); return *d->iconLabel->pixmap();}void QMessageBox::setIconPixmap(const QPixmap &pixmap){ Q_D(QMessageBox); d->iconLabel->setPixmap(pixmap); d->updateSize(); d->icon = NoIcon;}/*! \property QMessageBox::textFormat \brief the format of the text displayed by the message box The current text format used by the message box. See the \l Qt::TextFormat enum for an explanation of the possible options. The default format is Qt::AutoText. \sa setText()*/Qt::TextFormat QMessageBox::textFormat() const{ Q_D(const QMessageBox); return d->label->textFormat();}void QMessageBox::setTextFormat(Qt::TextFormat format){ Q_D(QMessageBox); d->label->setTextFormat(format); d->label->setWordWrap(format == Qt::RichText || (format == Qt::AutoText && Qt::mightBeRichText(d->label->text()))); d->updateSize();}/*! \reimp*/bool QMessageBox::event(QEvent *e){ bool result =QDialog::event(e); switch (e->type()) { case QEvent::LayoutRequest: d_func()->updateSize(); break; case QEvent::LanguageChange: d_func()->retranslateStrings(); break; default: break; } return result;}/*! \reimp*/void QMessageBox::resizeEvent(QResizeEvent *event){ QDialog::resizeEvent(event);}/*! \reimp*/void QMessageBox::closeEvent(QCloseEvent *e){ Q_D(QMessageBox); if (!d->detectedEscapeButton) { e->ignore(); return; } QDialog::closeEvent(e); d->clickedButton = d->detectedEscapeButton; setResult(d->execReturnCode(d->detectedEscapeButton));}/*! \reimp*/void QMessageBox::changeEvent(QEvent *ev){ Q_D(QMessageBox); switch (ev->type()) { case QEvent::StyleChange: { if (d->icon != NoIcon) setIcon(d->icon);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -