📄 qapplication.3qt
字号:
.)l.SH "void QApplication::sendPostedEvents () \fC[static]\fR"Dispatches all posted events..SH "void QApplication::sendPostedEvents ( QObject * receiver, int event_type ) \fC[static]\fR"Immediately dispatches all events which have been previously enqueued with QApplication::postEvent() and which are for the object \fIreceiver\fR and have the \fIevent_type.\fR.PPSome event compression may occur. Note that events from the window system are \fInot\fR dispatched by this function..SH "QString QApplication::sessionId () const"Returns the identifier of the current session..PPIf the application has been restored from an earlier session, this identifier is the same as it was in that previous session..PPThe session identifier is guaranteed to be unique for both different applications and different instances of the same application..PPSee also isSessionRestored(), commitData() and saveState()..SH "void QApplication::setColorSpec ( int spec ) \fC[static]\fR"Sets the color specification for the application to \fIspec.\fR.PPThe color specification controls how your application allocates colors when run on a display with a limited amount of colors, i.e. 8 bit / 256 color displays..PPThe color specification must be set before you create the QApplication object..PPThe choices are:.TP\fCQApplication::NormalColor.\fR This is the default color allocation strategy. Use this choice if your application uses buttons, menus, texts and pixmaps with few colors. With this choice, the application uses system global colors. This works fine for most applications under X11, but on Windows machines it may cause dithering of non-standard colors..TP\fCQApplication::CustomColor.\fR Use this choice if your application needs a small number of custom colors. On X11, this choice is the same as NormalColor. On Windows, Qt creates a Windows palette, and allocates colors in it on demand..TP\fCQApplication::ManyColor.\fR Use this choice if your application is very color hungry (e.g. it wants thousands of colors). Under X11 the effect is: .TPFor 256-color displays which have at best a 256 color true color visual, the default visual is used, and colors are allocated from a color cube. The color cube is the 6x6x6 (216 color) "Web palette", but the number of colors can be changed by the \fI-ncols\fR option. The user can force the application to use the true color visual by the -visual option..TPFor 256-color displays which have a true color visual with more than 256 colors, use that visual. Silicon Graphics X servers have this feature, for example. They provide an 8 bit visual by default but can deliver true color when asked. On Windows, Qt creates a Windows palette, and fills it with a color cube..PPBe aware that the CustomColor and ManyColor choices may lead to colormap flashing: The foreground application gets (most) of the available colors, while the background windows will look less good..PPExample:.PP.nf.br int main( int argc, char **argv ).br {.br QApplication::setColorSpec( QApplication::ManyColor );.br QApplication a( argc, argv );.br ....br }.fi.PPQColor provides more functionality for controlling color allocation and freeing up certain colors. See QColor::enterAllocContext() for more information..PPTo see what mode you end up with, you can call QColor::numBitPlanes() once the QApplication object exists. A value greater than 8 (typically 16, 24 or 32) means true color..PPThe color cube used by Qt are all those colors with red, green, and blue components of either 0x00, 0x33, 0x66, 0x99, 0xCC, or 0xFF..PPSee also colorSpec(), QColor::numBitPlanes() and QColor::enterAllocContext()..PPExamples:.(lshowimg/main.cpp themes/main.cpp tetrix/tetrix.cpp helpviewer/main.cpp.)l.SH "void QApplication::setCursorFlashTime ( int msecs ) \fC[static]\fR"Sets the text cursor's flash time to \fImsecs\fR milliseconds. The flash time is the time required to display, invert and restore the caret display: A full flash cycle. Usually, the text cursor is displayed for \fImsecs/2\fR milliseconds, then hidden for \fImsecs/2\fR milliseconds, but this may vary..PPNote that on Microsoft Windows, calling this function sets the cursor flash time for all windows..PPSee also cursorFlashTime()..SH "void QApplication::setDefaultCodec ( QTextCodec * codec )"If the literal quoted text in the program is not in the Latin1 encoding, this function can be used to set the appropriate encoding. For example, software developed by Korean programmers might use eucKR for all the text in the program, in which case main() would be:.PP.nf.br main(int argc, char** argv).br {.br QApplication app(argc, argv);.br ... install any additional codecs ....br app.setDefaultCodec( QTextCodec::codecForName("eucKR") );.br ....br }.fi.PPNote that this is \fInot\fR the way to select the encoding that the \fIuser\fR has chosen. For example, to convert an application containing literal English strings to Korean, all that is needed is for the English strings to be passed through tr() and for translation files to be loaded. For details of internationalization, see the Qt Internationalization documentation..PPNote also that some Qt built-in classes call tr() with various strings. These strings are in English, so for a full translation, a codec would be required for these strings..SH "void QApplication::setDesktopSettingsAware ( bool on ) \fC[static]\fR"By default, Qt will try to get the current standard colors, fonts etc. from the underlying window system's desktop settings (resources), and use them for all relevant widgets. This behavior can be switched off by calling this function with \fIon\fR set to FALSE..PPThis static function must be called before creating the QApplication object, like this:.PP.nf.br int main( int argc, char** argv ) {.br QApplication::setDesktopSettingsAware( FALSE ); // I know better than the user.br QApplication myApp( argc, argv ); // gimme default fonts & colors.br ....br }.fi.PPSee also desktopSettingsAware()..SH "void QApplication::setDoubleClickInterval ( int ms ) \fC[static]\fR"Sets the time limit that distinguishes a double click from two consecutive mouse clicks to \fIms\fR milliseconds..PPNote that on Microsoft Windows, calling this function sets the double click interval for all windows..PPSee also doubleClickInterval()..SH "void QApplication::setEffectEnabled ( Qt::UIEffect effect, bool enable = TRUE ) \fC[static]\fR"Enables the UI effect \fIeffect\fR if \fIenable\fR is TRUE, otherwise the effect will not be used..PPSee also isEffectEnabled(), Qt::UIEffect and setDesktopSettingsAware()..SH "void QApplication::setFont ( const QFont & font, bool informWidgets=FALSE, const char * className = 0 ) \fC[static]\fR"Changes the default application font to \fIfont.\fR If \fIinformWidgets\fR is TRUE, then existing widgets are informed about the change and thus may adjust themselves to the new application setting. Otherwise the change only affects newly created widgets. If \fIclassName\fR is passed, the change applies only to classes that inherit \fIclassName\fR (as reported by QObject::inherits())..PPOn application start-up, the default font depends on the window system. It can vary both with window system version and with locale. This function lets you override it. Note that overriding it may be a bad idea, for example some locales need extra-big fonts to support their special characters..PPSee also font(), fontMetrics() and QWidget::setFont()..PPExamples:.(lshowimg/main.cpp desktop/desktop.cpp qfd/qfd.cpp.)l.SH "void QApplication::setGlobalMouseTracking ( bool enable ) \fC[static]\fR"Enables global mouse tracking if \fIenable\fR is TRUE or disables it if \fIenable\fR is FALSE..PPEnabling global mouse tracking makes it possible for widget event filters or application event filters to get all mouse move events, even when no button is depressed. This is useful for special GUI elements, e.g. tool tips..PPGlobal mouse tracking does not affect widgets and their mouseMoveEvent(). For a widget to get mouse move events when no button is depressed, it must do QWidget::setMouseTracking(TRUE)..PPThis function uses an internal counter. Each setGlobalMouseTracking(TRUE) must have a corresponding setGlobalMouseTracking(FALSE):.PP.nf.br // at this point global mouse tracking is off.br QApplication::setGlobalMouseTracking( TRUE );.br QApplication::setGlobalMouseTracking( TRUE );.br QApplication::setGlobalMouseTracking( FALSE );.br // at this point it's still on.br QApplication::setGlobalMouseTracking( FALSE );.br // but now it's off.fi.PPSee also hasGlobalMouseTracking() and QWidget::hasMouseTracking()..SH "void QApplication::setGlobalStrut ( const QSize & strut ) \fC[static]\fR"Sets the application strut to \fIstrut.\fR No GUI-element that can be interacted with should be smaller than the provided size. This should be considered when reimplementing items that may be used on touch-screens or with similar IO-devices..PPExample:.PP.nf.br QSize& WidgetClass::sizeHint() const.br {.br return QSize( 80, 25 ).expandedTo( QApplication::globalStrut() );.br }.fi.PPSee also golbalStrut()..SH "void QApplication::setMainWidget ( QWidget * mainWidget ) \fC[virtual]\fR"Sets the main widget of the application..PPThe main widget is like any other, in most respects except that if it is deleted, the application exits..PPYou need not have a main widget; connecting lastWindowClosed() to quit() is another alternative..PPFor X11, this function also resizes and moves the main widget according to the \fI-geometry\fR command-line option, so you should set the default geometry (using QWidget::setGeometry()) before calling setMainWidget()..PPSee also mainWidget(), exec() and quit()..PPExamples:.(lrangecontrols/main.cpp iconview/main.cpp validator/main.cpp themes/main.cpp listviews/main.cpp aclock/main.cpp checklists/main.cpp drawlines/connect.cpp dclock/main.cpp mainlyQt/editor.cpp xform/xform.cpp cursor/cursor.cpp layout/layout.cpp buttongroups/main.cpp life/main.cpp i18n/main.cpp drawdemo/drawdemo.cpp lineedits/main.cpp popup/popup.cpp fileiconview/main.cpp listbox/main.cpp menu/menu.cpp progress/progress.cpp scribble/main.cpp qmag/qmag.cpp tabdialog/main.cpp splitter/splitter.cpp progressbar/main.cpp tooltip/main.cpp richtext/main.cpp forever/forever.cpp rot13/rot13.cpp xml/tagreader.)l-with-features/tagreader.cppqfd/qfd.cpp addressbook/main.cpp picture/picture.cpp hello/main.cpp listboxcombo/main.cpp biff/main.cpp tictac/main.cpp customlayout/main.cpp dirview/main.cpp.SH "void QApplication::setOverrideCursor ( const QCursor & cursor, bool replace=FALSE ) \fC[static]\fR"Sets the application override cursor to \fIcursor.\fR.PPApplication override cursors are intended for showing the user that the application is in a special state, for example during an operation that might take some time..PPThis cursor will be displayed in all the widgets of the application until restoreOverrideCursor() or another setOverrideCursor() is called..PPApplication cursors are stored on an internal stack. setOverrideCursor() pushes the cursor onto the stack, and restoreOverrideCursor() pops the active cursor off the stack. Every setOverrideCursor() must eventually be followed by a corresponding restoreOverrideCursor(), otherwise the stack will never be emptied..PPIf \fIreplace\fR is TRUE, the new cursor will replace the last override cursor (the stack keeps its depth). If \fIreplace\fR is FALSE, the new stack is pushed onto the top of the stack..PPExample:.PP.nf.br QApplication::setOverrideCursor( Qt::waitCursor );.br calculateHugeMandelbrot(); // lunch time....br QApplication::restoreOverrideCursor();.fi.PPSee also overrideCursor(), restoreOverrideCursor() and QWidget::setCursor()..SH "void QApplication::setPalette ( const QPalette & palette, bool informWidgets=FALSE, const char * className = 0 ) \fC[static]\fR"Changes the default application palette to \fIpalette.\fR If \fIinformWidgets\fR is TRUE, then existing widgets are informed about the change and thus may adjust themselves to the new application setting. Otherwise the change only affects newly created widgets. If \fIclassName\fR is passed, the change applies only to classes that inherit \fIclassName\fR (as reported by QObject::inherits())..PPThe palette may be changed according to the current GUI style in QStyle::polish()..PPSee also QWidget::setPalette(), palette() and QStyle::polish()..SH "void QApplication::setStartDragDistance ( int l ) \fC[static]\fR"Sets the distance after which a drag should start..PPSee also startDragDistance()..SH "void QApplication::setStartDragTime ( int ms ) \fC[static]\fR"Sets the time after which a drag should start..PPSee also startDragTime()..SH "void QApplication::setStyle ( QStyle * style ) \fC[static]\fR"Sets the application GUI style to \fIstyle.\fR Ownership of the style object is transferred to QApplication, so QApplication will delete the style object on application exit or when a new style is set..PPExample usage:.PP.nf.br QApplication::setStyle( new QWindowStyle );.fi.PPWhen switching application styles, the color palette is set back to the initial colors or the system defaults. This is necessary since certain styles have to adapt the color palette to be fully style-guide compliant..PPSee also style(), QStyle, setPalette() and desktopSettingsAware()..SH "void QApplication::setWheelScrollLines ( int n ) \fC[static]\fR"Sets the number of lines to scroll when the mouse wheel is rotated..PPIf this number exceeds the number of visible lines in a certain widget, the widget should interpret the scroll operation as a single page up / page down operation instead..PPSee also wheelScrollLines()..SH "void QApplication::setWinStyleHighlightColor ( const QColor & c ) \fC[static]\fR"\fBThis function is obsolete.\fR It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code..PPSets the color used to mark selections in windows style for all widgets in the application. Will repaint all widgets if the color is changed..PPThe default color is \fCdarkBlue.\fR.PPSee also winStyleHighlightColor()..SH "int QApplication::startDragDistance () \fC[static]\fR"If you support drag'n'drop in you application and a drag should start after a mouse click and after moving the mouse a certain distance, you should use the value which this method returns as the distance. So if the mouse position of the click is stored in \fCstartPos\fR and the current position (e.g. in the mouse move event) is \fCcurrPos,\fR you can find out if a drag should be started with a code like this:.PP.nf.br if ( ( startPos - currPos ).manhattanLength() > QApplication::startDragDistance() ).br startTheDrag();.fi.PPQt internally uses this value too, e.g. in the QFileDialog..PPThe default value is set to 4 pixels..PPSee also setStartDragDistance(), startDragTime() and QPoint::manhattanLength()..SH "int QApplication::startDragTime () \fC[static]\fR"If you support drag'n'drop in you application and a drag should start after a mouse click and after a certain time elapsed, you should use the value which this method returns as delay (in ms)..PPQt internally uses also this delay e.g. in QMultiLineEdit for starting a drag..PPThe default value is set to 500 ms..PPSee also setStartDragTime() and startDragDistance()..SH "bool QApplication::startingUp () \fC[static]\fR"Returns TRUE if an application object has not been created yet..PPSee also closingDown()..SH "QStyle& QApplication::style () \fC[static]\fR"Returns the style object of the application..PPSee also setStyle() and QStyle..SH "void QApplication::syncX () \fC[static]\fR"Synchronizes with the X server in the X11 implementation. This normally takes some time. Does nothing on other platforms..PPSee also flushX()..SH "QWidgetList * QApplication::topLevelWidgets () \fC[static]\fR"Returns a list of the top level widgets in the application..PPThe list is created using \fCnew\fR and must be deleted by the caller..PPThe list is empty (QList::isEmpty()) if there are no top level widgets..PPNote that some of the top level widgets may be hidden, for example the tooltip if no tooltip is currently shown..PPExample:.PP.nf.br //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -