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

📄 qmessagebox.3qt

📁 这个是Linux的qt源代码
💻 3QT
📖 第 1 页 / 共 3 页
字号:
.br        // abort.br        break;.br    }.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.br    QMessageBox::critical( 0, "Application name here",.br        QString("An internal error occurred. Please ") +.br        "call technical support at 1234-56789 and report\\n"+.br        "these numbers:\\n\\n" + errorDetails +.br        "\\n\\nApplication will now exit." );.br.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.br    QMessageBox::about( this, "About <Application>",.br        "<Application> is a <one-paragraph blurb>\\n\\n".br        "Copyright 1991-2003 Such-and-such. ".br        "<License words here.>\\n\\n".br        "For technical support, call 1234-56789 or see\\n".br        "http://www.such-and-such.com/Application/\\n" );.br.fi.PPSee about() for more information..PPIf you want your users to know that the application is built using Qt (so they know that 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 use custom button texts:.PP.nf.br    QMessageBox 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 );.br    mb.setButtonText( QMessageBox::Yes, "Save" );.br    mb.setButtonText( QMessageBox::No, "Discard" );.br    switch( 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    }.br.fi.PPQMessageBox defines two enum types: Icon and an unnamed button type. Icon defines the Question, Information, Warning, and Critical icons for each GUI style. It is used by the constructor and by the static member functions question(), 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.TPYesAll.TPNoAll.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..PPThe text(), icon() and iconPixmap() functions provide access to the current text and pixmap of the message box. The setText(), setIcon() and setIconPixmap() let you change it. The difference between setIcon() and setIconPixmap() is that the former accepts a QMessageBox::Icon and can be used to set standard icons, whereas the latter accepts a QPixmap and can be used to set custom icons..PPsetButtonText() and buttonText() provide access to the buttons..PPQMessageBox has no signals or slots..PP.ce 1.B "[Image Omitted]".PP.ce 1.B "[Image Omitted]".PPSee also QDialog, Isys on error messages, GUI Design Handbook: Message Box, and Dialog Classes..SS "Member Type Documentation".SH "QMessageBox::Icon"This enum has the following values:.TP\fCQMessageBox::NoIcon\fR - the message box does not have any icon..TP\fCQMessageBox::Question\fR - an icon indicating that the message is asking a question..TP\fCQMessageBox::Information\fR - an icon indicating that the message is nothing out of the ordinary..TP\fCQMessageBox::Warning\fR - an icon indicating that the message is a warning, but can be dealt with..TP\fCQMessageBox::Critical\fR - an icon indicating that the message represents a critical problem..PP.SH MEMBER FUNCTION DOCUMENTATION.SH "QMessageBox::QMessageBox ( QWidget * parent = 0, const char * name = 0 )"Constructs a message box with no text and a button with the label" OK"..PPIf \fIparent\fR is 0, the message box becomes an application-global modal dialog box. If \fIparent\fR is a widget, the message box becomes modal relative to \fIparent\fR..PPThe \fIparent\fR and \fIname\fR arguments are passed to the QDialog constructor..SH "QMessageBox::QMessageBox ( 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 )"Constructs a message box with a \fIcaption\fR, a \fItext\fR, an \fIicon\fR, and up to three buttons..PPThe \fIicon\fR must be one of the following:.TPQMessageBox::NoIcon.TPQMessageBox::Question.TPQMessageBox::Information.TPQMessageBox::Warning.TPQMessageBox::Critical.PPEach button, \fIbutton0\fR, \fIbutton1\fR and \fIbutton2\fR, can have one of the following values:.TPQMessageBox::NoButton.TPQMessageBox::Ok.TPQMessageBox::Cancel.TPQMessageBox::Yes.TPQMessageBox::No.TPQMessageBox::Abort.TPQMessageBox::Retry.TPQMessageBox::Ignore.TPQMessageBox::YesAll.TPQMessageBox::NoAll.PPUse QMessageBox::NoButton for the later parameters to have fewer than three buttons in your message box. If you don't specify any buttons at all, QMessageBox will provide an Ok button..PPOne of the buttons can be OR-ed with the \fCQMessageBox::Default\fR flag to make it the default button (clicked when Enter is pressed)..PPOne of the buttons can be OR-ed with the \fCQMessageBox::Escape\fR flag to make it the cancel or close button (clicked when Escape is pressed)..PPExample:.PP.nf.br    QMessageBox mb( "Application Name",.br        "Hardware failure.\\n\\nDisk error detected\\nDo you want to stop?",.br        QMessageBox::Question,.br        QMessageBox::Yes | QMessageBox::Default,.br        QMessageBox::No  | QMessageBox::Escape.br        QMessageBox::NoButton );.br    if ( mb.exec() == QMessageBox::No ).br        // try again.br.fi.PPIf \fIparent\fR is 0, the message box becomes an application-global modal dialog box. If \fIparent\fR is a widget, the message box becomes modal relative to \fIparent\fR..PPIf \fImodal\fR is TRUE the message box is modal; otherwise it is modeless..PPThe \fIparent\fR, \fIname\fR, \fImodal\fR, and \fIf\fR arguments are passed to the QDialog constructor..PPSee also caption, text, and icon..SH "QMessageBox::~QMessageBox ()"Destroys the message box..SH "void QMessageBox::about ( QWidget * parent, const QString & caption, const QString & text )\fC [static]\fR"Displays a simple about box with caption \fIcaption\fR and text \fItext\fR. The about box's parent is \fIparent\fR..PPabout() looks for a suitable icon in four locations: <ol type=1>.TPIt prefers parent->icon() if that exists..TPIf not, it tries the top-level widget containing \fIparent\fR..TPIf that fails, it tries the main widget..TPAs a last resort it uses the Information icon..PPThe about box has a single button labelled "OK"..PPSee also QWidget::icon and QApplication::mainWidget()..PPExamples:.)l action/application.cpp, application/application.cpp, chart/chartform.cpp, helpviewer/helpwindow.cpp, mdi/application.cpp, menu/menu.cpp, and themes/themes.cpp..SH "void QMessageBox::aboutQt ( QWidget * parent, const QString & caption = QString::null )\fC [static]\fR"Displays a simple message box about Qt, with caption \fIcaption\fR and centered over \fIparent\fR (if \fIparent\fR is not 0). The message includes the version number of Qt being used by the application..PPThis is useful for inclusion in the Help menu of an application. See the examples/menu/menu.cpp example..PPQApplication provides this functionality as a slot..PPSee also QApplication::aboutQt()..PPExamples:.)l action/application.cpp, application/application.cpp, chart/chartform.cpp, helpviewer/helpwindow.cpp, menu/menu.cpp, themes/themes.cpp, and trivial/trivial.cpp..SH "void QMessageBox::adjustSize ()\fC [virtual]\fR"Adjusts the size of the message box to fit the contents just before QDialog::exec() or QDialog::show() is called..PPThis function will not be called if the message box has been explicitly resized before showing it..PPReimplemented from QWidget..SH "QString QMessageBox::buttonText ( int button ) const"Returns the text of the message box button \fIbutton\fR, or QString::null if the message box does not contain the button..PPSee also setButtonText()..SH "int QMessageBox::critical ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1, int button2 = 0 )\fC [static]\fR"Opens a critical message box with the caption \fIcaption\fR and the text \fItext\fR. The dialog may have up to three buttons. Each of the button parameters, \fIbutton0\fR, \fIbutton1\fR and \fIbutton2\fR may be set to one of the following values:.TPQMessageBox::NoButton.TPQMessageBox::Ok.TPQMessageBox::Cancel.TPQMessageBox::Yes.TPQMessageBox::No.TPQMessageBox::Abort.TP

⌨️ 快捷键说明

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