⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qmessagebox.3qt

📁 Linux下的基于X11的图形开发环境。
💻 3QT
📖 第 1 页 / 共 2 页
字号:
'\" t.TH QMessageBox 3qt "9 December 2002" "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 }".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 \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. 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 a simple messages, or two or even three buttons for questions..PPThere are static functions for common cases..PPExamples:.)l.PPIf a program is unable to find a supporting file, but can do perfectly well without it:.PP.nf.brQMessageBox::information( this, "Application name",.br    "Unable to find the user preferences file.\\n".br    "The factory default will be used instead." );.fi.PPwarning() can be used to tell the user about unusual errors, or errors which can't be easily fixed:.PP.nf.brswitch( 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}.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 strongly 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.brswitch( 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 Alt+C pressed or Escape pressed.br        // don't exit.br        break;.br}.fi.PPThe application name is used as the window caption in accordance with the Microsoft recommendation. The 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 (in a perfect world, they are) and they certainly can be hard to correct. This example uses predefined buttons instead of hard-coded button texts:.PP.nf.brswitch( 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.br        // abort.br        break;.br}.fi.PPThe critical() function should be reserved for critical errors. In this example errorDetails is a QString or const char*, and QString is used to concatenate several strings:.PP.nf.brQMessageBox::critical( 0, "Application name here",.br        QString("An internal error occurred. Please ") +.br        "call technical support at 123456789 and report\\n"+.br        "these numbers:\\n\\n" + errorDetails +.br        "\\n\\n<Application> will now exit." );.fi.PPIn this example an OK button is displayed..PPQMessageBox provides a very simple About box, which displays an appropriate icon and the string you provide:.PP.nf.brQMessageBox::about( this, "About <Application>",.br        "<Application> is a <one-paragraph blurb>\\n\\n".br        "Copyright 1951-2002 Such-and-such.  ".br        "<License words here.>\\n\\n".br        "For technical support, call 123456789 or see\\n".br        "http://www.such-and-such.com/Application/\\n" );.fi.PPSee about() for more information..PPIf you want your users to know that the application is built using Qt (so that they know you use high quality tools:) you might like to add an "About Qt" menu option under the Help menu to invoke aboutQt()..PPIf none of the standard message boxes is suitable, you can create a QMessageBox from scratch and with custom button texts:.PP.nf.brQMessageBox mb( "Application name here",.br        "Saving the file will overwrite the original file on the disk.\\n".br        "Do you really want to save?",.br        QMessageBox::Information,.br        QMessageBox::Yes | QMessageBox::Default,.br        QMessageBox::No,.br        QMessageBox::Cancel | QMessageBox::Escape );.brmb.setButtonText( QMessageBox::Yes, "Save" );.brmb.setButtonText( QMessageBox::No, "Discard" );.brswitch( mb.exec() ) {.br    case QMessageBox::Yes:.br        // save and exit.br        break;.br    case QMessageBox::No:.br        // exit without saving.br        break;.br    case QMessageBox::Cancel:.br        // don't save and don't exit.br        break;.br}.fi.PPQMessageBox defines two enum types: Icon and an unnamed button type. Icon defines the Information, Warning, and Critical icons for each GUI style. It is used by the constructor and by the static member functions information(), warning() and critical(). A function called standardIcon() gives you access to the various icons..PPThe button types are:.TPOk - the default for single-button message boxes.TPCancel - note that this is \fInot\fR automatically Escape.TPYes.TPNo.TPAbort.TPRetry.TPIgnore.PPButton types can be combined with two modifiers by using OR, '|':.TPDefault - makes pressing Enter equivalent to clicking this button. Normally used with Ok, Yes or similar..TPEscape - makes pressing Escape equivalent to clicking this button. Normally used with Abort, Cancel or similar..PP

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -