A native message dialog. 更多...
import 语句: | import Qt.labs.platform 1.1 |
Since: | Qt 5.8 |
继承: | Dialog |
The MessageDialog type provides a QML API for native platform message dialogs.
A message dialog is used to inform the user, or ask the user a question. A message dialog displays a primary text 以向用户发出状况警报, 情报文本 以进一步阐述警报或向用户询问问题,和可选 细节文本 to provide even more data if the user requests it. A message box can also display a configurable set of buttons 为接受用户响应。
To show a message dialog, construct an instance of MessageDialog, set the desired properties, and call open() .
MessageDialog { buttons: MessageDialog.Ok text: "The document has been modified." }
用户必须点击 OK button to dismiss the message dialog. A modal message dialog blocks the rest of the GUI until the message is dismissed.
A more elaborate approach than just alerting the user to an event is to also ask the user what to do about it. Store the question in the 情报文本 property, and specify the buttons property to the set of buttons you want as the set of user responses. The buttons are specified by combining values using the bitwise OR operator. The display order for the buttons is platform dependent.
MessageDialog { text: "The document has been modified." informativeText: "Do you want to save your changes?" buttons: MessageDialog.Ok | MessageDialog.Cancel onAccepted: document.save() }
clicked() signal passes the information of which button was clicked.
A native platform message dialog is currently available on the following platforms:
The Qt Labs Platform module uses Qt Widgets as a fallback on platforms that do not have a native implementation available. Therefore, applications that use types from the Qt Labs Platform module should link to QtWidgets and use QApplication 而不是 QGuiApplication .
To link against the QtWidgets library, add the following to your qmake project file:
QT += widgets
Create an instance of
QApplication
in
main()
:
#include <QApplication> #include <QQmlApplicationEngine> int main(int argc, char *argv[]) { QApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); }
注意: Types in Qt.labs modules are not guaranteed to remain compatible in future versions.
buttons : flags |
This property holds a combination of buttons that are used by the message dialog. The default value is
MessageDialog.NoButton
.
Possible flags:
常量 | 描述 |
---|---|
MessageDialog.Ok
|
An "OK" button defined with the
AcceptRole
.
|
MessageDialog.Open
|
An "Open" button defined with the
AcceptRole
.
|
MessageDialog.Save
|
A "Save" button defined with the
AcceptRole
.
|
MessageDialog.Cancel
|
A "Cancel" button defined with the
RejectRole
.
|
MessageDialog.Close
|
A "Close" button defined with the
RejectRole
.
|
MessageDialog.Discard
|
A "Discard" or "Don't Save" button, depending on the platform, defined with the
DestructiveRole
.
|
MessageDialog.Apply
|
An "Apply" button defined with the
ApplyRole
.
|
MessageDialog.Reset
|
A "Reset" button defined with the
ResetRole
.
|
MessageDialog.RestoreDefaults
|
A "Restore Defaults" button defined with the
ResetRole
.
|
MessageDialog.Help
|
A "Help" button defined with the
HelpRole
.
|
MessageDialog.SaveAll
|
A "Save All" button defined with the
AcceptRole
.
|
MessageDialog.Yes
|
A "Yes" button defined with the
YesRole
.
|
MessageDialog.YesToAll
|
A "Yes to All" button defined with the
YesRole
.
|
MessageDialog.No
|
A "No" button defined with the
NoRole
.
|
MessageDialog.NoToAll
|
A "No to All" button defined with the
NoRole
.
|
MessageDialog.Abort
|
An "Abort" button defined with the
RejectRole
.
|
MessageDialog.Retry
|
A "Retry" button defined with the
AcceptRole
.
|
MessageDialog.Ignore
|
An "Ignore" button defined with the
AcceptRole
.
|
MessageDialog.NoButton
|
The dialog has no buttons. |
另请参阅 clicked() .
detailedText : string |
This property holds the text to be displayed in the details area.
另请参阅 text and informativeText .
informativeText : string |
This property holds the informative text that provides a fuller description for the message.
Informative text can be used to expand upon the text to give more information to the user.
另请参阅 text and detailedText .
text : string |
This property holds the text to be displayed on the message dialog.
另请参阅 informativeText and detailedText .
abortClicked () |
此信号被发射当 Abort 被点击。
注意:
相应处理程序是
onAbortClicked
.
applyClicked () |
此信号被发射当 Apply 被点击。
注意:
相应处理程序是
onApplyClicked
.
cancelClicked () |
此信号被发射当 Cancel 被点击。
注意:
相应处理程序是
onCancelClicked
.
clicked ( button ) |
This signal is emitted when a dialog button 被点击。
注意:
相应处理程序是
onClicked
.
另请参阅 buttons .
closeClicked () |
此信号被发射当 Close 被点击。
注意:
相应处理程序是
onCloseClicked
.
discardClicked () |
此信号被发射当 Discard 被点击。
注意:
相应处理程序是
onDiscardClicked
.
helpClicked () |
此信号被发射当 帮助 被点击。
注意:
相应处理程序是
onHelpClicked
.
ignoreClicked () |
此信号被发射当 Ignore 被点击。
注意:
相应处理程序是
onIgnoreClicked
.
noClicked () |
此信号被发射当 No 被点击。
注意:
相应处理程序是
onNoClicked
.
noToAllClicked () |
此信号被发射当 No To All 被点击。
注意:
相应处理程序是
onNoToAllClicked
.
okClicked () |
此信号被发射当 Ok 被点击。
注意:
相应处理程序是
onOkClicked
.
openClicked () |
此信号被发射当 打开 被点击。
注意:
相应处理程序是
onOpenClicked
.
resetClicked () |
此信号被发射当 Reset 被点击。
注意:
相应处理程序是
onResetClicked
.
restoreDefaultsClicked () |
此信号被发射当 Restore Defaults 被点击。
注意:
相应处理程序是
onRestoreDefaultsClicked
.
retryClicked () |
此信号被发射当 Retry 被点击。
注意:
相应处理程序是
onRetryClicked
.
saveAllClicked () |
此信号被发射当 Save All 被点击。
注意:
相应处理程序是
onSaveAllClicked
.
saveClicked () |
此信号被发射当 Save 被点击。
注意:
相应处理程序是
onSaveClicked
.
yesClicked () |
此信号被发射当 Yes 被点击。
注意:
相应处理程序是
onYesClicked
.
yesToAllClicked () |
此信号被发射当 Yes To All 被点击。
注意:
相应处理程序是
onYesToAllClicked
.