📄 qapplication.3qt
字号:
Examples:.(li18n/main.cpp.)l.SH "bool QApplication::isSessionRestored () const"Returns whether the application has been restored from an earlier session..PPSee also: sessionId(), commitData() and saveState()..SH "void QApplication::lastWindowClosed () \fC[signal]\fR"This signal is emitted when the user has closed the last remaining top level window..PPThe signal is very useful when your application has many top level widgets but no main widget. You can then connect it to the quit() slot..PPFor convenience, transient toplevel widgets such as popup menus and dialogs are omitted..PPSee also: mainWidget(), topLevelWidgets(), QWidget::isTopLevel() and QWidget::close()..SH "QWidget * QApplication::mainWidget () const"Returns the main application widget, or 0 if there is not a defined main widget..PPSee also: setMainWidget()..SH "bool QApplication::notify ( QObject * receiver, QEvent * event ) \fC[virtual]\fR"Sends \fIevent\fR to \fIreceiver:\fR \fCreceiver->event( event )\fR Returns the value that is returned from the receiver's event handler..PPReimplementing this virtual function is one of five ways to process an event: .IP 1Reimplementing this function. Very powerful, you get \fIcomplete\fR control, but of course only one subclass can be qApp..IP 2Installing an event filter on qApp. Such an event filter gets to process all events for all widgets, so it's just as powerful as reimplementing notify(), and in this way it's possible to have more than one application-global event filter. Global event filter get to see even mouse events for disabled widgets, and if global mouse tracking is enabled, mouse move events for all widgets..IP 3Reimplementing QObject::event() (as QWidget does). If you do this you get tab key-presses, and you get to see the events before any widget-specific event filters..IP 4Installing an event filter on the object. Such an even filter gets all the events except Tab and Shift-Tab key presses..IP 5Finally, reimplementing paintEvent(), mousePressEvent() and so on. This is the normal, easiest and least powerful way. .PPSee also: QObject::event() and installEventFilter()..SH "QCursor * QApplication::overrideCursor () \fC[static]\fR"Returns the active application override cursor..PPThis function returns 0 if no application cursor has been defined (i.e. the internal cursor stack is empty)..PPSee also: setOverrideCursor() and restoreOverrideCursor()..SH "QPalette QApplication::palette ( const QWidget * w = 0 ) \fC[static]\fR"Returns a pointer to the default application palette. There is always an application palette, i.e. the returned pointer is guaranteed to be non-null..PPIf a widget is passed as argument, the default palette for the widget's class is returned. This may or may not be the application palette, but in most cases there won't be a special palette for certain types of widgets. An exception is the popup menu under Windows, when the user defined a special background color for menus in the display settings..PPSee also: setPalette() and QWidget::palette()..SH "void QApplication::polish ( QWidget * w ) \fC[virtual]\fR"Polishing of widgets..PPUsually widgets call this automatically when they are polished. It may be used to do some style-based central customization of widgets..PPNote that you are not limited to public functions of QWidget. Instead, based on meta information like QObject::className() you are able to customize any kind of widgets..PPThe default implementation sets a class specific font or palette if available and no font or palette has been set yet. Then it calls QStyle::polish()..PPSee also: QStyle::polish(), QWidget::polish(), setPalette() and setFont()..SH "void QApplication::postEvent ( QObject * receiver, QEvent * event ) \fC[static]\fR"Stores the event in a queue and returns immediately..PPThe event must be allocated on the heap, as it is deleted when the event has been posted..PPWhen control returns to the main event loop, all events that are stored in the queue will be sent using the notify() function..PPSee also: sendEvent()..SH "void QApplication::processEvents ()"Processes pending events, for 3 seconds or until there are no more events to process, then return..PPYou can call this function occasionally when your program is busy doing a long operation (e.g. copying a file)..PPSee also: processOneEvent(), exec() and QTimer..SH "void QApplication::processEvents ( int maxtime )"Processes pending events, for \fImaxtime\fR milliseconds or until there are no more events to process, then return..PPYou can call this function occasionally when you program is busy doing a long operation (e.g. copying a file)..PPSee also: processOneEvent(), exec() and QTimer..SH "void QApplication::processOneEvent ()"Waits for an event to occur, processes it, then returns..PPThis function is useful for adapting Qt to situations where the event processing must be grafted into existing program loops. Beware that using this function in new applications may be an indication of design problems..PPSee also: processEvents(), exec() and QTimer..SH "void QApplication::quit () \fC[slot]\fR"Tells the application to exit with return code 0 (success). Equivalent to calling QApplication::exit( 0 )..PPThis function is a slot, i.e. you may connect any signal to activate quit()..PPExample:.PP.nf.br QPushButton *quitButton = new QPushButton( "Quit" );.br connect( quitButton, SIGNAL(clicked()), qApp, SLOT(quit()) );.fi.PPSee also: exit() and aboutToQuit()..SH "void QApplication::removePostedEvents ( QObject * receiver ) \fC[static]\fR"Removes all events posted using postEvent() for \fIreceiver.\fR.PPThe events are \fInot\fR dispatched, simply removed from the queue. You should never need to call this function..SH "void QApplication::removeTranslator ( QTranslator * mf )"Removes \fImf\fR from the list of message files used by this application. Does not, of course, delete mf..PPSee also: installTranslator(), translate() and QObject::tr()..SH "void QApplication::restoreOverrideCursor () \fC[static]\fR"Restores the effect of setOverrideCursor()..PPIf setOverrideCursor() has been called twice, calling restoreOverrideCursor() will activate the first cursor set. Calling this function a second time restores the original widgets cursors..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 have an corresponding restoreOverrideCursor(), otherwise the stack will get out of sync. overrideCursor() returns 0 if the cursor stack is empty..PPSee also: setOverrideCursor() and overrideCursor()..SH "void QApplication::saveState ( QSessionManager & sm ) \fC[virtual]\fR"This function deals with session management It is invoked when the session manager wants the application to preserve its state for a future session..PPFor a text editor this would mean creating a temporary file that includes the current contents of the edit buffers, the location of the cursor and other aspects of the current editing session..PPNote that you should never exit the application within this function. Instead, the session manager may or may not do this afterwards, depending on the context. Futhermore, most session managers will very likely request a saved state immediately after the application has been started. This permits the session manager to learn about the application's restart policy..PP\fBImportant\fR.brWithin this function, no user interaction is possible, \fIunless\fR you ask the session manager \fIsm\fR for explicit permission. See QSessionManager::allowsInteraction() and QSessionManager::allowsErrorInteraction() for details..PPDetails about session management in general can be found here.PPSee also: isSessionRestored(), sessionId() and commitData()..SH "bool QApplication::sendEvent ( QObject * receiver, QEvent * event ) \fC[static]\fR"Sends an event directly to a receiver, using the notify() function. Returns the value that was returned from the event handler..PPSee also: postEvent() and notify()..PPExamples:.(lpopup/popup.cpp.)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.PPIf \fIreceiver\fR is 0, all objects get their events. If \fIevent_type\fR is 0, all types of events are dispatched..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. You must set the color specification 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 allocates system global colors. This work fine for most applications under X11, but on Windows machines it can cause dithering of non-standard colours in 256-color mode..IP.TP\fCQApplication::CustomColor.\fR Use this choice if your application needs a small number of custom colors. This choice only makes a difference on Windows - the application gets more colors when it is active, but the background windows look less good. Under X11 this is the same as \fCNormalColor.\fR Under Windows, Qt creates a Windows palette if the display supports 256 colors..IP.TP\fCQApplication::ManyColor.\fR Use this choice if your application is very color hungry (e.g. it wants thousands of colors). Under Windows, this is currently the same as \fCCustomColor.\fR 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 a 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 eample. They provide an 8 bit visual by default but can deliver true color when asked..IP.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 qbrowser/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 requried to display, invert and restore the caret display: A full flash cycle. Usually, the text cursor is displayed for \fImsecs/2\fR millisecnds, then hidden for \fImsecs/2\fR milliseconds..PPUnder windows, calling this function sets the double click interval 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..PPUnder windows, calling this function sets the double click interval for all windows..PPSee also: doubleClickInterval()..SH "void QApplication::setFont ( const QFont & font, bool updateAllWidgets=FALSE, const char * className = 0 ) \fC[static]\fR"Changes the default application font to \fIfont.\fR.PPThe default font depends on the underlying window system, under X Windows on the X server in use..PPIf \fIupdateAllWidgets\fR is TRUE, then the font of all existing widgets is set to \fIfont.\fR.PPIf a className is passed, then the font is only set for widgets that inherit this class in the sense of QObject::inherits().PPWidgets created after this call get \fIfont\fR as their font when they access it..PPSee also: font(), fontMetrics() and QWidget::setFont()..PPExamples:.(lshowimg/main.cpp tetrix/tetrix.cpp desktop/desktop.cpp movies/main.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 has an internal counter. Each setGlobalMouseTracking(TRUE) must have a corresponding setGlobalMouseTracking(FALSE)..PPSee also: hasGlobalMouseTracking() and QWidget::hasMouseTracking()..SH "void QApplication::setMainWidget ( QWidget * mainWidget ) \fC[virtual]\fR"Sets the main widget of the application..PPThe special thing about the main widget is that destroying the main widget (i.e. the program calls QWidget::close() or the user double-clicks the window close box) will leave the main event loop and exit the application..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 before calling setMainWidget()..PPSee also: mainWidget(), exec() and quit()..PPExamples:.(lrangecontrols/main.cpp validator/main.cpp themes/main.cpp listviews/main.cpp aclock/main.cpp checklists/main.cpp buttons_groups/main.cpp drawlines/connect.cpp dclock/main.cpp mainlyQt/editor.cpp xform/xform.cpp qiconview/main.cpp cursor/cursor.cpp layout/layout.cpp life/main.cpp i18n/main.cpp drawdemo/drawdemo.cpp lineedits/main.cpp popup/popup.cpp listbox/main.cpp menu/menu.cpp progress/progress.cpp scribble/main.cpp qmag/qmag.cpp table/main.cpp splitter/splitter.cpp progressbar/main.cpp richtext/main.cpp tooltip/main.cpp forever/forever.cpp rot13/rot13.cpp qfd/qfd.cpp addressbook/main.cpp picture/picture.cpp listbox_combo/main.cpp hello/main.cpp qfileiconview/main.cpp biff/main.cpp tictac/main.cpp customlayout/main.cpp dirview/main.cpp.)l.SH "void QApplication::setOverrideCursor ( const QCursor & cursor, bool replace=FALSE ) \fC[static]\fR"Sets the application override cursor to \fIcursor.\fR.PPApplication override cursor 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 application widgets 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 have an corresponding restoreOverrideCursor(), otherwise the stack will get out of sync. overrideCursor() returns 0 if the cursor stack is empty..PPIf \fIreplace\fR is TRUE, the new cursor will replace the last override cursor..PPExample:.PP.nf.br QApplication::setOverrideCursor( waitCursor );.br calculateHugeMandelbrot(); // lunch time....br QApplication::restoreOverrideCursor();.fi.PPSee also: overrideCursor(), restoreOverrideCursor() and QWidget::setCursor()..SH "void QApplication::setPalette ( const QPalette & palette, bool updateAllWidgets=FALSE, const char * className = 0 ) \fC[static]\fR"Changes the default application palette to \fIpalette.\fR.PPIf \fIupdateAllWidgets\fR is TRUE, then the palette of all existing widgets is set to \fIpalette.\fR.PPIf a className is passed, then the palette is only set for widgets that inherit this class in the sense of QObject::inherits().PPWidgets created after this call get \fIpalette\fR as their palette when they access it..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::setStyle ( QStyle * style ) \fC[static]\fR"Sets the application GUI style to \fIstyle.\fR.PPSee also: style() and QStyle..PPExamples:.(lthemes/main.cpp.)l.SH "void QApplication::setWinStyleHighlightColor ( const QColor & c ) \fC[static]\fR"\fBThis function is obsolete.\fR It is provided to keep old programs working. We strongly advise against using it in new code.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -