📄 qmessagebox.3qt
字号:
'\" t.TH QMessageBox 3qt "10 November 2003" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQMessageBox \- Modal dialog with a short message, an icon, and some buttons.SH SYNOPSIS\fC#include <qmessagebox.h>\fR.PPInherits QDialog..PP.SS "Public Members".in +1c.ti -1c.BI "enum \fBIcon\fR { NoIcon = 0, Information = 1, Warning = 2, Critical = 3, Question = 4 }".br.ti -1c.BI "\fBQMessageBox\fR ( QWidget * parent = 0, const char * name = 0 )".br.ti -1c.BI "\fBQMessageBox\fR ( const QString & caption, const QString & text, Icon icon, int button0, int button1, int button2, QWidget * parent = 0, const char * name = 0, bool modal = TRUE, WFlags f = WStyle_DialogBorder )".br.ti -1c.BI "\fB~QMessageBox\fR ()".br.ti -1c.BI "QString \fBtext\fR () const".br.ti -1c.BI "void \fBsetText\fR ( const QString & )".br.ti -1c.BI "Icon \fBicon\fR () const".br.ti -1c.BI "void \fBsetIcon\fR ( Icon )".br.ti -1c.BI "const QPixmap * \fBiconPixmap\fR () const".br.ti -1c.BI "void \fBsetIconPixmap\fR ( const QPixmap & )".br.ti -1c.BI "QString \fBbuttonText\fR ( int button ) const".br.ti -1c.BI "void \fBsetButtonText\fR ( int button, const QString & text )".br.ti -1c.BI "virtual void \fBadjustSize\fR ()".br.ti -1c.BI "TextFormat \fBtextFormat\fR () const".br.ti -1c.BI "void \fBsetTextFormat\fR ( TextFormat )".br.in -1c.SS "Static Public Members".in +1c.ti -1c.BI "int \fBinformation\fR ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1 = 0, int button2 = 0 )".br.ti -1c.BI "int \fBinformation\fR ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text = QString::null, const QString & button1Text = QString::null, const QString & button2Text = QString::null, int defaultButtonNumber = 0, int escapeButtonNumber = -1 )".br.ti -1c.BI "int \fBquestion\fR ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1 = 0, int button2 = 0 )".br.ti -1c.BI "int \fBquestion\fR ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text = QString::null, const QString & button1Text = QString::null, const QString & button2Text = QString::null, int defaultButtonNumber = 0, int escapeButtonNumber = -1 )".br.ti -1c.BI "int \fBwarning\fR ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1, int button2 = 0 )".br.ti -1c.BI "int \fBwarning\fR ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text = QString::null, const QString & button1Text = QString::null, const QString & button2Text = QString::null, int defaultButtonNumber = 0, int escapeButtonNumber = -1 )".br.ti -1c.BI "int \fBcritical\fR ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1, int button2 = 0 )".br.ti -1c.BI "int \fBcritical\fR ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text = QString::null, const QString & button1Text = QString::null, const QString & button2Text = QString::null, int defaultButtonNumber = 0, int escapeButtonNumber = -1 )".br.ti -1c.BI "void \fBabout\fR ( QWidget * parent, const QString & caption, const QString & text )".br.ti -1c.BI "void \fBaboutQt\fR ( QWidget * parent, const QString & caption = QString::null )".br.ti -1c.BI "int message ( const QString & caption, const QString & text, const QString & buttonText = QString::null, QWidget * parent = 0, const char * = 0 ) \fI(obsolete)\fR".br.ti -1c.BI "bool query ( const QString & caption, const QString & text, const QString & yesButtonText = QString::null, const QString & noButtonText = QString::null, QWidget * parent = 0, const char * = 0 ) \fI(obsolete)\fR".br.ti -1c.BI "QPixmap standardIcon ( Icon icon, GUIStyle style ) \fI(obsolete)\fR".br.ti -1c.BI "QPixmap \fBstandardIcon\fR ( Icon icon )".br.in -1c.SS "Properties".in +1c.ti -1c.BI "Icon \fBicon\fR - the message box's icon".br.ti -1c.BI "QPixmap \fBiconPixmap\fR - the current icon".br.ti -1c.BI "QString \fBtext\fR - the message box text to be displayed".br.ti -1c.BI "TextFormat \fBtextFormat\fR - the format of the text displayed by the message box".br.in -1c.SH DESCRIPTIONThe QMessageBox class provides a modal dialog with a short message, an icon, and some buttons..PPMessage boxes are used to provide informative messages and to ask simple questions..PPQMessageBox provides a range of different messages, arranged roughly along two axes: severity and complexity..PPSeverity is <center>.nf.TSl - l. Question For message boxes that ask a question as part of normal operation. Some style guides recommend using Information for this purpose. Information For message boxes that are part of normal operation. Warning For message boxes that tell the user about unusual errors. Critical.TE.fi</center>.PPThe message box has a different icon for each of the severity levels..PPComplexity is one button (OK) for simple messages, or two or even three buttons for questions..PPThere are static functions for the most common cases..PPExamples:.)l.PPIf a program is unable to find a supporting file, but can do perfectly well without it:.PP.nf.br QMessageBox::information( this, "Application name",.br "Unable to find the user preferences file.\\n".br "The factory default will be used instead." );.br.fi.PPquestion() is useful for simple yes/no questions:.PP.nf.br if ( QFile::exists( filename ) &&.br QMessageBox::question(.br this,.br tr("Overwrite File? -- Application Name"),.br tr("A file called %1 already exists.".br "Do you want to overwrite it?").br .arg( filename ),.br tr("&Yes"), tr("&No"),.br QString::null, 0, 1 ) ).br return false;.br.fi.PPwarning() can be used to tell the user about unusual errors, or errors which can't be easily fixed:.PP.nf.br switch( QMessageBox::warning( this, "Application name",.br "Could not connect to the <mumble> server.\\n".br "This program can't function correctly ".br "without the server.\\n\\n",.br "Retry",.br "Quit", 0, 0, 1 ) ) {.br case 0: // The user clicked the Retry again button or pressed Enter.br // try again.br break;.br case 1: // The user clicked the Quit or pressed Escape.br // exit.br break;.br }.br.fi.PPThe text part of all message box messages can be either rich text or plain text. If you specify a rich text formatted string, it will be rendered using the default stylesheet. See QStyleSheet::defaultSheet() for details. With certain strings that contain XML meta characters, the auto-rich text detection may fail, interpreting plain text incorrectly as rich text. In these rare cases, use QStyleSheet::convertFromPlainText() to convert your plain text string to a visually equivalent rich text string or set the text format explicitly with setTextFormat()..PPNote that the Microsoft Windows User Interface Guidelines recommend using the application name as the window's caption..PPBelow are more examples of how to use the static member functions. After these examples you will find an overview of the non-static member functions..PPExiting a program is part of its normal operation. If there is unsaved data the user probably should be asked if they want to save the data. For example:.PP.nf.br switch( QMessageBox::information( this, "Application name here",.br "The document contains unsaved changes\\n".br "Do you want to save the changes before exiting?",.br "&Save", "&Discard", "Cancel",.br 0, // Enter == button 0.br 2 ) ) { // Escape == button 2.br case 0: // Save clicked or Alt+S pressed or Enter pressed..br // save.br break;.br case 1: // Discard clicked or Alt+D pressed.br // don't save but exit.br break;.br case 2: // Cancel clicked or Escape pressed.br // don't exit.br break;.br }.br.fi.PPThe Escape button cancels the entire exit operation, and pressing Enter causes the changes to be saved before the exit occurs..PPDisk full errors are unusual and they certainly can be hard to correct. This example uses predefined buttons instead of hard-coded button texts:.PP.nf.br switch( QMessageBox::warning( this, "Application name here",.br "Could not save the user preferences,\\n".br "because the disk is full. You can delete\\n".br "some files and press Retry, or you can\\n".br "abort the Save Preferences operation.",.br QMessageBox::Retry | QMessageBox::Default,.br QMessageBox::Abort | QMessageBox::Escape )) {.br case QMessageBox::Retry: // Retry clicked or Enter pressed.br // try again.br break;.br case QMessageBox::Abort: // Abort clicked or Escape pressed
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -