Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QMessageBox Class

TheQMessageBox class provides a modal dialog for informing the user or for asking the user a question and receiving an answer.More...

Header:#include <QMessageBox>
Inherits:QDialog

Public Types

enumButtonRole { InvalidRole, AcceptRole, RejectRole, DestructiveRole, ..., ResetRole }
enumIcon { NoIcon, Question, Information, Warning, Critical }
enumStandardButton { Ok, Open, Save, Cancel, ..., ButtonMask }
flagsStandardButtons

Properties

Public Functions

QMessageBox(QWidget * parent = 0)
QMessageBox(Icon icon, const QString & title, const QString & text, StandardButtons buttons = NoButton, QWidget * parent = 0, Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint)
~QMessageBox()
voidaddButton(QAbstractButton * button, ButtonRole role)
QPushButton *addButton(const QString & text, ButtonRole role)
QPushButton *addButton(StandardButton button)
QAbstractButton *button(StandardButton which) const
ButtonRolebuttonRole(QAbstractButton * button) const
QList<QAbstractButton *>buttons() const
QAbstractButton *clickedButton() const
QPushButton *defaultButton() const
QStringdetailedText() const
QAbstractButton *escapeButton() const
Iconicon() const
QPixmapiconPixmap() const
QStringinformativeText() const
voidopen(QObject * receiver, const char * member)
voidremoveButton(QAbstractButton * button)
voidsetDefaultButton(QPushButton * button)
voidsetDefaultButton(StandardButton button)
voidsetDetailedText(const QString & text)
voidsetEscapeButton(QAbstractButton * button)
voidsetEscapeButton(StandardButton button)
voidsetIcon(Icon)
voidsetIconPixmap(const QPixmap & pixmap)
voidsetInformativeText(const QString & text)
voidsetStandardButtons(StandardButtons buttons)
voidsetText(const QString & text)
voidsetTextFormat(Qt::TextFormat format)
voidsetWindowModality(Qt::WindowModality windowModality)
voidsetWindowTitle(const QString & title)
StandardButtonstandardButton(QAbstractButton * button) const
StandardButtonsstandardButtons() const
QStringtext() const
Qt::TextFormattextFormat() const

Reimplemented Public Functions

virtual voidsetVisible(bool visible)
  • 8 public functions inherited fromQDialog
  • 220 public functions inherited fromQWidget
  • 29 public functions inherited fromQObject
  • 12 public functions inherited fromQPaintDevice

Public Slots

intexec()
  • 5 public slots inherited fromQDialog
  • 19 public slots inherited fromQWidget
  • 1 public slot inherited fromQObject

Signals

voidbuttonClicked(QAbstractButton * button)

Static Public Members

voidabout(QWidget * parent, const QString & title, const QString & text)
voidaboutQt(QWidget * parent, const QString & title = QString())
StandardButtoncritical(QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton)
StandardButtoninformation(QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton)
StandardButtonquestion(QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton)
StandardButtonwarning(QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton)
  • 4 static public members inherited fromQWidget
  • 7 static public members inherited fromQObject

Reimplemented Protected Functions

virtual voidchangeEvent(QEvent * ev)
virtual voidcloseEvent(QCloseEvent * e)
virtual boolevent(QEvent * e)
virtual voidkeyPressEvent(QKeyEvent * e)
virtual voidresizeEvent(QResizeEvent * event)
virtual voidshowEvent(QShowEvent * e)
  • 7 protected functions inherited fromQDialog
  • 37 protected functions inherited fromQWidget
  • 8 protected functions inherited fromQObject
  • 1 protected function inherited fromQPaintDevice

Additional Inherited Members

  • 7 protected functions inherited fromQDialog
  • 37 protected functions inherited fromQWidget
  • 8 protected functions inherited fromQObject
  • 1 protected function inherited fromQPaintDevice
  • 1 protected slot inherited fromQWidget

Detailed Description

TheQMessageBox class provides a modal dialog for informing the user or for asking the user a question and receiving an answer.

A message box displays a primarytext to alert the user to a situation, aninformative text to further explain the alert or to ask the user a question, and an optionaldetailed text to provide even more data if the user requests it. A message box can also display anicon andstandard buttons for accepting a user response.

Two APIs for usingQMessageBox are provided, the property-based API, and the static functions. Calling one of the static functions is the simpler approach, but it is less flexible than using the property-based API, and the result is less informative. Using the property-based API is recommended.

The Property-based API

To use the property-based API, construct an instance ofQMessageBox, set the desired properties, and callexec() to show the message. The simplest configuration is to set only themessage text property.

QMessageBox msgBox;msgBox.setText("The document has been modified.");msgBox.exec();

The user must click theOK button to dismiss the message box. The rest of the GUI is blocked until the message box is dismissed.

A better approach than just alerting the user to an event is to also ask the user what to do about it. Store the question in theinformative text property, and set thestandard buttons property to the set of buttons you want as the set of user responses. The buttons are specified by combining values fromStandardButtons using the bitwise OR operator. The display order for the buttons is platform-dependent. For example, on Windows,Save is displayed to the left ofCancel, whereas on Mac OS, the order is reversed.

Mark one of your standard buttons to be yourdefault button.

QMessageBox msgBox;msgBox.setText("The document has been modified.");msgBox.setInformativeText("Do you want to save your changes?");msgBox.setStandardButtons(QMessageBox::Save|QMessageBox::Discard|QMessageBox::Cancel);msgBox.setDefaultButton(QMessageBox::Save);int ret= msgBox.exec();

This is the approach recommended in theMac OS X Guidelines. Similar guidelines apply for the other platforms, but note the different ways theinformative text is handled for different platforms.

Theexec() slot returns theStandardButtons value of the button that was clicked.

switch (ret) {caseQMessageBox::Save:// Save was clickedbreak;caseQMessageBox::Discard:// Don't Save was clickedbreak;caseQMessageBox::Cancel:// Cancel was clickedbreak;default:// should never be reachedbreak;}

To give the user more information to help him answer the question, set thedetailed text property. If thedetailed text property is set, theShow Details... button will be shown.

Clicking theShow Details... button displays the detailed text.

Rich Text and the Text Format Property

Thedetailed text property is always interpreted as plain text. Themain text andinformative text properties can be either plain text or rich text. These strings are interpreted according to the setting of thetext format property. The default setting isauto-text.

Note that for some plain text strings containing XML meta-characters, the auto-text rich text detection test may fail causing your plain text string to be interpreted incorrectly as rich text. In these rare cases, use Qt::convertFromPlainText() to convert your plain text string to a visually equivalent rich text string, or set thetext format property explicitly withsetTextFormat().

Severity Levels and the Icon and Pixmap Properties

QMessageBox supports four predefined message severity levels, or message types, which really only differ in the predefined icon they each show. Specify one of the four predefined message types by setting theicon property to one of thepredefined icons. The following rules are guidelines:

QuestionFor asking a question during normal operations.

InformationFor reporting information about normal operations.

WarningFor reporting non-critical errors.

CriticalFor reporting critical errors.

Predefined icons are not defined byQMessageBox, but provided by the style. The default value isNo Icon. The message boxes are otherwise the same for all cases. When using a standard icon, use the one recommended in the table, or use the one recommended by the style guidelines for your platform. If none of the standard icons is right for your message box, you can use a custom icon by setting theicon pixmap property instead of setting theicon property.

In summary, to set an icon, useeithersetIcon() for one of the standard icons,orsetIconPixmap() for a custom icon.

The Static Functions API

Building message boxes with the static functions API, although convenient, is less flexible than using the property-based API, because the static function signatures lack parameters for setting theinformative text anddetailed text properties. One work-around for this has been to use thetitle parameter as the message box main text and thetext parameter as the message box informative text. Because this has the obvious drawback of making a less readable message box, platform guidelines do not recommend it. TheMicrosoft Windows User Interface Guidelines recommend using theapplication name as thewindow's title, which means that if you have an informative text in addition to your main text, you must concatenate it to thetext parameter.

Note that the static function signatures have changed with respect to their button parameters, which are now used to set thestandard buttons and thedefault button.

Static functions are available for creatinginformation(),question(),warning(), andcritical() message boxes.

int ret=QMessageBox::warning(this, tr("My Application"),                               tr("The document has been modified.\n""Do you want to save your changes?"),QMessageBox::Save|QMessageBox::Discard|QMessageBox::Cancel,QMessageBox::Save);

TheStandard Dialogs example shows how to useQMessageBox and the other built-in Qt dialogs.

Advanced Usage

If thestandard buttons are not flexible enough for your message box, you can use theaddButton() overload that takes a text and a ButtonRoleto to add custom buttons. TheButtonRole is used byQMessageBox to determine the ordering of the buttons on screen (which varies according to the platform). You can test the value ofclickedButton() after callingexec(). For example,

QMessageBox msgBox;QPushButton*connectButton= msgBox.addButton(tr("Connect"),QMessageBox::ActionRole);QPushButton*abortButton= msgBox.addButton(QMessageBox::Abort);msgBox.exec();if (msgBox.clickedButton()== connectButton) {// connect}elseif (msgBox.clickedButton()== abortButton) {// abort}

Default and Escape Keys

The default button (i.e., the button activated whenEnter is pressed) can be specified usingsetDefaultButton(). If a default button is not specified,QMessageBox tries to find one based on thebutton roles of the buttons used in the message box.

The escape button (the button activated whenEsc is pressed) can be specified usingsetEscapeButton(). If an escape button is not specified,QMessageBox tries to find one using these rules:

  1. If there is only one button, it is the button activated whenEsc is pressed.
  2. If there is aCancel button, it is the button activated whenEsc is pressed.
  3. If there is exactly one button having eitherthe Reject role or thethe No role, it is the button activated whenEsc is pressed.

When an escape button can't be determined using these rules, pressingEsc has no effect.

See alsoQDialogButtonBox,GUI Design Handbook: Message Box,Standard Dialogs Example, andApplication Example.

Member Type Documentation

enum QMessageBox::ButtonRole

This enum describes the roles that can be used to describe buttons in the button box. Combinations of these roles are as flags used to describe different aspects of their behavior.

ConstantValueDescription
QMessageBox::InvalidRole-1The button is invalid.
QMessageBox::AcceptRole0Clicking the button causes the dialog to be accepted (e.g. OK).
QMessageBox::RejectRole1Clicking the button causes the dialog to be rejected (e.g. Cancel).
QMessageBox::DestructiveRole2Clicking the button causes a destructive change (e.g. for Discarding Changes) and closes the dialog.
QMessageBox::ActionRole3Clicking the button causes changes to the elements within the dialog.
QMessageBox::HelpRole4The button can be clicked to request help.
QMessageBox::YesRole5The button is a "Yes"-like button.
QMessageBox::NoRole6The button is a "No"-like button.
QMessageBox::ApplyRole8The button applies current changes.
QMessageBox::ResetRole7The button resets the dialog's fields to default values.

See alsoStandardButton.

enum QMessageBox::Icon

This enum has the following values:

ConstantValueDescription
QMessageBox::NoIcon0the message box does not have any icon.
QMessageBox::Question4an icon indicating that the message is asking a question.
QMessageBox::Information1an icon indicating that the message is nothing out of the ordinary.
QMessageBox::Warning2an icon indicating that the message is a warning, but can be dealt with.
QMessageBox::Critical3an icon indicating that the message represents a critical problem.

enum QMessageBox::StandardButton
flags QMessageBox::StandardButtons

These enums describe flags for standard buttons. Each button has a definedButtonRole.

ConstantValueDescription
QMessageBox::Ok0x00000400An "OK" button defined with theAcceptRole.
QMessageBox::Open0x00002000A "Open" button defined with theAcceptRole.
QMessageBox::Save0x00000800A "Save" button defined with theAcceptRole.
QMessageBox::Cancel0x00400000A "Cancel" button defined with theRejectRole.
QMessageBox::Close0x00200000A "Close" button defined with theRejectRole.
QMessageBox::Discard0x00800000A "Discard" or "Don't Save" button, depending on the platform, defined with theDestructiveRole.
QMessageBox::Apply0x02000000An "Apply" button defined with theApplyRole.
QMessageBox::Reset0x04000000A "Reset" button defined with theResetRole.
QMessageBox::RestoreDefaults0x08000000A "Restore Defaults" button defined with theResetRole.
QMessageBox::Help0x01000000A "Help" button defined with theHelpRole.
QMessageBox::SaveAll0x00001000A "Save All" button defined with theAcceptRole.
QMessageBox::Yes0x00004000A "Yes" button defined with theYesRole.
QMessageBox::YesToAll0x00008000A "Yes to All" button defined with theYesRole.
QMessageBox::No0x00010000A "No" button defined with theNoRole.
QMessageBox::NoToAll0x00020000A "No to All" button defined with theNoRole.
QMessageBox::Abort0x00040000An "Abort" button defined with theRejectRole.
QMessageBox::Retry0x00080000A "Retry" button defined with theAcceptRole.
QMessageBox::Ignore0x00100000An "Ignore" button defined with theAcceptRole.
QMessageBox::NoButton0x00000000An invalid button.

The following values are obsolete:

ConstantValueDescription
QMessageBox::YesAllYesToAllUse YesToAll instead.
QMessageBox::NoAllNoToAllUse NoToAll instead.
QMessageBox::Default0x00000100Use thedefaultButton argument ofinformation(),warning(), etc. instead, or callsetDefaultButton().
QMessageBox::Escape0x00000200CallsetEscapeButton() instead.
QMessageBox::FlagMask0x00000300 
QMessageBox::ButtonMask~FlagMask 

This enum was introduced or modified in Qt 4.2.

The StandardButtons type is a typedef forQFlags<StandardButton>. It stores an OR combination of StandardButton values.

See alsoButtonRole andstandardButtons.

Property Documentation

detailedText :QString

This property holds the text to be displayed in the details area.

The text will be interpreted as a plain text.

By default, this property contains an empty string.

This property was introduced in Qt 4.2.

Access functions:

QStringdetailedText() const
voidsetDetailedText(const QString & text)

See alsoQMessageBox::text andQMessageBox::informativeText.

icon :Icon

This property holds the message box's icon.

The icon of the message box can be specified with one of the values:

The default isQMessageBox::NoIcon.

The pixmap used to display the actual icon depends on the currentGUI style. You can also set a custom pixmap for the icon by setting theicon pixmap property.

Access functions:

Iconicon() const
voidsetIcon(Icon)

See alsoiconPixmap.

iconPixmap :QPixmap

This property holds 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.

By default, this property is undefined.

Access functions:

QPixmapiconPixmap() const
voidsetIconPixmap(const QPixmap & pixmap)

See alsoicon.

informativeText :QString

This property holds the informative text that provides a fuller description for the message.

Infromative text can be used to expand upon thetext() to give more information to the user. On the Mac, this text appears in small system font below thetext(). On other platforms, it is simply appended to the existing text.

By default, this property contains an empty string.

This property was introduced in Qt 4.2.

Access functions:

QStringinformativeText() const
voidsetInformativeText(const QString & text)

See alsoQMessageBox::text andQMessageBox::detailedText.

standardButtons :StandardButtons

This property holds collection of standard buttons in the message box.

This property controls which standard buttons are used by the message box.

By default, this property contains no standard buttons.

This property was introduced in Qt 4.2.

Access functions:

StandardButtonsstandardButtons() const
voidsetStandardButtons(StandardButtons buttons)

See alsoaddButton().

text :QString

This property holds 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 (QMessageBox::textFormat). The default setting isQt::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.

Access functions:

QStringtext() const
voidsetText(const QString & text)

See alsotextFormat,QMessageBox::informativeText, andQMessageBox::detailedText.

textFormat :Qt::TextFormat

This property holds the format of the text displayed by the message box.

The current text format used by the message box. See theQt::TextFormat enum for an explanation of the possible options.

The default format isQt::AutoText.

Access functions:

Qt::TextFormattextFormat() const
voidsetTextFormat(Qt::TextFormat format)

See alsosetText().

Member Function Documentation

QMessageBox::QMessageBox(QWidget * parent = 0)

Constructs a message box with no text and no buttons.parent is passed to theQDialog constructor.

On Mac OS X, if you want your message box to appear as aQt::Sheet of itsparent, set the message box'swindow modality toQt::WindowModal or useopen(). Otherwise, the message box will be a standard dialog.

QMessageBox::QMessageBox(Icon icon, constQString & title, constQString & text,StandardButtons buttons = NoButton,QWidget * parent = 0,Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint)

Constructs a message box with the givenicon,title,text, and standardbuttons. Standard or custom buttons can be added at any time usingaddButton(). Theparent andf arguments are passed to theQDialog constructor.

The message box is anapplication modal dialog box.

On Mac OS X, ifparent is not 0 and you want your message box to appear as aQt::Sheet of that parent, set the message box'swindow modality toQt::WindowModal (default). Otherwise, the message box will be a standard dialog.

See alsosetWindowTitle(),setText(),setIcon(), andsetStandardButtons().

QMessageBox::~QMessageBox()

Destroys the message box.

[static]void QMessageBox::about(QWidget * parent, constQString & title, constQString & text)

Displays a simple about box with titletitle and texttext. The about box's parent isparent.

about() looks for a suitable icon in four locations:

  1. It prefersparent->icon() if that exists.
  2. If not, it tries the top-level widget containingparent.
  3. If that fails, it tries theactive window.
  4. As a last resort it uses the Information icon.

The about box has a single button labelled "OK". On Mac OS X, the about box is popped up as a modeless window; on other platforms, it is currently application modal.

See alsoQWidget::windowIcon() andQApplication::activeWindow().

[static]void QMessageBox::aboutQt(QWidget * parent, constQString & title = QString())

Displays a simple message box about Qt, with the giventitle and centered overparent (ifparent is not 0). The message includes the version number of Qt being used by the application.

This is useful for inclusion in theHelp menu of an application, as shown in theMenus example.

QApplication provides this functionality as a slot.

On Mac OS X, the about box is popped up as a modeless window; on other platforms, it is currently application modal.

See alsoQApplication::aboutQt().

void QMessageBox::addButton(QAbstractButton * button,ButtonRole role)

Adds the givenbutton to the message box with the specifiedrole.

This function was introduced in Qt 4.2.

See alsoremoveButton(),button(), andsetStandardButtons().

QPushButton * QMessageBox::addButton(constQString & text,ButtonRole role)

This is an overloaded function.

Creates a button with the giventext, adds it to the message box for the specifiedrole, and returns it.

This function was introduced in Qt 4.2.

QPushButton * QMessageBox::addButton(StandardButton button)

This is an overloaded function.

Adds a standardbutton to the message box if it is valid to do so, and returns the push button.

This function was introduced in Qt 4.2.

See alsosetStandardButtons().

QAbstractButton * QMessageBox::button(StandardButton which) const

Returns a pointer corresponding to the standard buttonwhich, or 0 if the standard button doesn't exist in this message box.

This function was introduced in Qt 4.2.

See alsostandardButtons andstandardButton().

[signal]void QMessageBox::buttonClicked(QAbstractButton * button)

This signal is emitted whenever a button is clicked inside theQMessageBox. The button that was clicked in returned inbutton.

ButtonRole QMessageBox::buttonRole(QAbstractButton * button) const

Returns the button role for the specifiedbutton. This function returnsInvalidRole ifbutton is 0 or has not been added to the message box.

This function was introduced in Qt 4.5.

See alsobuttons() andaddButton().

QList<QAbstractButton *> QMessageBox::buttons() const

Returns a list of all the buttons that have been added to the message box.

This function was introduced in Qt 4.5.

See alsobuttonRole(),addButton(), andremoveButton().

[virtual protected]void QMessageBox::changeEvent(QEvent * ev)

Reimplemented fromQWidget::changeEvent().

QAbstractButton * QMessageBox::clickedButton() const

Returns the button that was clicked by the user, or 0 if the user hit theEsc key and noescape button was set.

Ifexec() hasn't been called yet, returns 0.

Example:

QMessageBox messageBox(this);QAbstractButton*disconnectButton=      messageBox.addButton(tr("Disconnect"),QMessageBox::ActionRole);...messageBox.exec();if (messageBox.clickedButton()== disconnectButton) {...}

This function was introduced in Qt 4.2.

See alsostandardButton() andbutton().

[virtual protected]void QMessageBox::closeEvent(QCloseEvent * e)

Reimplemented fromQWidget::closeEvent().

[static]StandardButton QMessageBox::critical(QWidget * parent, constQString & title, constQString & text,StandardButtons buttons = Ok,StandardButton defaultButton = NoButton)

Opens a critical message box with the giventitle andtext in front of the specifiedparent widget.

The standardbuttons are added to the message box.defaultButton specifies the button used whenEnter is pressed.defaultButton must refer to a button that was given inbuttons. IfdefaultButton isQMessageBox::NoButton,QMessageBox chooses a suitable default automatically.

Returns the identity of the standard button that was clicked. IfEsc was pressed instead, theescape button is returned.

The message box is anapplication modal dialog box.

Warning: Do not deleteparent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of theQMessageBox constructors.

This function was introduced in Qt 4.2.

See alsoquestion(),warning(), andinformation().

QPushButton * QMessageBox::defaultButton() const

Returns the button that should be the message box'sdefault button. Returns 0 if no default button was set.

This function was introduced in Qt 4.2.

See alsosetDefaultButton(),addButton(), andQPushButton::setDefault().

QAbstractButton * QMessageBox::escapeButton() const

Returns the button that is activated when escape is pressed.

By default,QMessageBox attempts to automatically detect an escape button as follows:

  1. If there is only one button, it is made the escape button.
  2. If there is aCancel button, it is made the escape button.
  3. On Mac OS X only, if there is exactly one button with the roleQMessageBox::RejectRole, it is made the escape button.

When an escape button could not be automatically detected, pressingEsc has no effect.

This function was introduced in Qt 4.2.

See alsosetEscapeButton() andaddButton().

[virtual protected]bool QMessageBox::event(QEvent * e)

Reimplemented fromQObject::event().

[slot]int QMessageBox::exec()

Shows the message box as amodal dialog, blocking until the user closes it.

When using aQMessageBox with standard buttons, this functions returns aStandardButton value indicating the standard button that was clicked. When usingQMessageBox with custom buttons, this function returns an opaque value; useclickedButton() to determine which button was clicked.

Note:Theresult() function returns alsoStandardButton value instead ofQDialog::DialogCode

Users cannot interact with any other window in the same application until they close the dialog, either by clicking a button or by using a mechanism provided by the window system.

See alsoshow() andresult().

[static]StandardButton QMessageBox::information(QWidget * parent, constQString & title, constQString & text,StandardButtons buttons = Ok,StandardButton defaultButton = NoButton)

Opens an information message box with the giventitle andtext in front of the specifiedparent widget.

The standardbuttons are added to the message box.defaultButton specifies the button used whenEnter is pressed.defaultButton must refer to a button that was given inbuttons. IfdefaultButton isQMessageBox::NoButton,QMessageBox chooses a suitable default automatically.

Returns the identity of the standard button that was clicked. IfEsc was pressed instead, theescape button is returned.

The message box is anapplication modal dialog box.

Warning: Do not deleteparent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of theQMessageBox constructors.

This function was introduced in Qt 4.2.

See alsoquestion(),warning(), andcritical().

[virtual protected]void QMessageBox::keyPressEvent(QKeyEvent * e)

Reimplemented fromQWidget::keyPressEvent().

void QMessageBox::open(QObject * receiver, constchar * member)

This is an overloaded function.

Opens the dialog and connects itsfinished() orbuttonClicked() signal to the slot specified byreceiver andmember. If the slot inmember has a pointer for its first parameter the connection is tobuttonClicked(), otherwise the connection is tofinished().

The signal will be disconnected from the slot when the dialog is closed.

[static]StandardButton QMessageBox::question(QWidget * parent, constQString & title, constQString & text,StandardButtons buttons = Ok,StandardButton defaultButton = NoButton)

Opens a question message box with the giventitle andtext in front of the specifiedparent widget.

The standardbuttons are added to the message box.defaultButton specifies the button used whenEnter is pressed.defaultButton must refer to a button that was given inbuttons. IfdefaultButton isQMessageBox::NoButton,QMessageBox chooses a suitable default automatically.

Returns the identity of the standard button that was clicked. IfEsc was pressed instead, theescape button is returned.

The message box is anapplication modal dialog box.

Warning: Do not deleteparent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of theQMessageBox constructors.

This function was introduced in Qt 4.2.

See alsoinformation(),warning(), andcritical().

void QMessageBox::removeButton(QAbstractButton * button)

Removesbutton from the button box without deleting it.

This function was introduced in Qt 4.2.

See alsoaddButton() andsetStandardButtons().

[virtual protected]void QMessageBox::resizeEvent(QResizeEvent * event)

Reimplemented fromQWidget::resizeEvent().

void QMessageBox::setDefaultButton(QPushButton * button)

Sets the message box'sdefault button tobutton.

This function was introduced in Qt 4.2.

See alsodefaultButton(),addButton(), andQPushButton::setDefault().

void QMessageBox::setDefaultButton(StandardButton button)

Sets the message box'sdefault button tobutton.

This function was introduced in Qt 4.3.

See alsoaddButton() andQPushButton::setDefault().

void QMessageBox::setEscapeButton(QAbstractButton * button)

Sets the button that gets activated when theEscape key is pressed tobutton.

This function was introduced in Qt 4.2.

See alsoescapeButton(),addButton(), andclickedButton().

void QMessageBox::setEscapeButton(StandardButton button)

Sets the buttons that gets activated when theEscape key is pressed tobutton.

This function was introduced in Qt 4.3.

See alsoaddButton() andclickedButton().

[virtual]void QMessageBox::setVisible(bool visible)

Reimplemented fromQWidget::setVisible().

void QMessageBox::setWindowModality(Qt::WindowModality windowModality)

This function shadowsQWidget::setWindowModality().

Sets the modality of the message box towindowModality.

On Mac OS X, if the modality is set toQt::WindowModal and the message box has a parent, then the message box will be aQt::Sheet, otherwise the message box will be a standard dialog.

This function was introduced in Qt 4.2.

void QMessageBox::setWindowTitle(constQString & title)

This function shadowsQWidget::setWindowTitle().

Sets the title of the message box totitle. On Mac OS X, the window title is ignored (as required by the Mac OS X Guidelines).

This function was introduced in Qt 4.2.

[virtual protected]void QMessageBox::showEvent(QShowEvent * e)

Reimplemented fromQWidget::showEvent().

StandardButton QMessageBox::standardButton(QAbstractButton * button) const

Returns the standard button enum value corresponding to the givenbutton, orNoButton if the givenbutton isn't a standard button.

This function was introduced in Qt 4.2.

See alsobutton() andstandardButtons().

[static]StandardButton QMessageBox::warning(QWidget * parent, constQString & title, constQString & text,StandardButtons buttons = Ok,StandardButton defaultButton = NoButton)

Opens a warning message box with the giventitle andtext in front of the specifiedparent widget.

The standardbuttons are added to the message box.defaultButton specifies the button used whenEnter is pressed.defaultButton must refer to a button that was given inbuttons. IfdefaultButton isQMessageBox::NoButton,QMessageBox chooses a suitable default automatically.

Returns the identity of the standard button that was clicked. IfEsc was pressed instead, theescape button is returned.

The message box is anapplication modal dialog box.

Warning: Do not deleteparent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of theQMessageBox constructors.

This function was introduced in Qt 4.2.

See alsoquestion(),information(), andcritical().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp