📄 qapplication.3qt
字号:
.br app.setDefaultCodec( QTextCodec::codecForName("eucKR") );.br ....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 use the current standard colors, fonts etc. from the underlying window system's desktop settings, 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 ); // give me default fonts & colors.br ....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::setEnableRemoteControl ( bool enable, const QUuid appId = QUuid ( ) )"Enables remote access to the application if \fIenable\fR is set to TRUE. You can use the \fIappId\fR to give your application a unique identification that can be used by the remote control. If \fIenable\fR is set to FALSE a currently remote access is terminated. Remote control access is disabled by default. You can call this function any time after having created the application..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 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 the default font; but overriding may be a bad idea, for example some locales need extra-large fonts to support their special characters..PPSee also font(), fontMetrics() and QWidget::font..PPExamples:.)l desktop/desktop.cpp, i18n/main.cpp, qfd/qfd.cpp, showimg/main.cpp, themes/metal.cpp and themes/themes.cpp..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.br.fi.PPSee also hasGlobalMouseTracking() and QWidget::mouseTracking..SH "void QApplication::setGlobalStrut ( const QSize & strut )\fC [static]\fR"Sets the application's global strut to \fIstrut\fR..PPThe strut is a size object whose dimensions are the minimum that any GUI element that the user can interact with should have. For example no button should be resized to be smaller than the global strut size..PPThe strut size should be considered when reimplementing GUI controls that may be used on touch-screens or similar IO-devices..PPExample:.PP.nf.br QSize& WidgetClass::sizeHint() const.br {.br return QSize( 80, 25 ).expandedTo( QApplication::globalStrut() );.br }.br.fi.PPSee also globalStrut()..SH "void QApplication::setLibraryPaths ( const QStringList & paths )\fC [static]\fR"Sets the list of directories to search when loading libraries to \fIpaths\fR. If \fIpaths\fR is empty, the path list is unchanged, otherwise all existing paths will be deleted and the path list will consist of the paths given in \fIpaths\fR..PPSee also libraryPaths(), addLibraryPath(), removeLibraryPath() and QLibrary..SH "void QApplication::setMainWidget ( QWidget * mainWidget )\fC [virtual]\fR"Sets the main widget of the application to \fImainWidget\fR..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:.)l action/actiongroup/main.cpp, biff/main.cpp, fonts/simple-qfont-demo/simple-qfont-demo.cpp, life/main.cpp, t1/main.cpp, t4/main.cpp and xml/outliner/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();.br.fi.PPSee also overrideCursor(), restoreOverrideCursor() and QWidget::cursor..PPExample: showimg/showimg.cpp..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 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::palette, palette() and QStyle::polish()..PPExamples:.)l i18n/main.cpp, themes/metal.cpp, themes/themes.cpp and themes/wood.cpp..SH "void QApplication::setReverseLayout ( bool b )\fC [static]\fR"If \fIb\fR is TRUE, all dialogs and widgets will be laid out in a mirrored fashion, as required by right to left languages such as Hebrew and Arabic..PPSee also reverseLayout()..SH "void QApplication::setStartDragDistance ( int l )\fC [static]\fR"Sets the distance after which a drag should start to \fIl\fR ms..PPSee also startDragDistance()..SH "void QApplication::setStartDragTime ( int ms )\fC [static]\fR"Sets the time after which a drag should start to \fIms\fR ms..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 );.br.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()..PPExample: themes/themes.cpp..SH "QStyle * QApplication::setStyle ( const QString & style )\fC [static]\fR"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPUses QStyleFactory to create a QStyle object for \fIstyle\fR..SH "void QApplication::setWheelScrollLines ( int n )\fC [static]\fR"Sets the number of lines to scroll when the mouse wheel is rotated to \fIn\fR..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. 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 and 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 code like this:.PP.nf.br if ( ( startPos - currPos ).manhattanLength() > QApplication::startDragDistance() ).br startTheDrag();.br.fi.PPQt internally uses this value too, e.g. in the QFileDialog..PPThe default value is 4 pixels..PPSee also setStartDragDistance(), startDragTime() and QPoint::manhattanLength()..SH "int QApplication::startDragTime ()\fC [static]\fR"If you support drag and 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 QTextView or QLineEdit for starting a drag..PPThe default value is 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 (QPtrList::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 // Show all hidden top level widgets..br QWidgetList *list = QApplication::topLevelWidgets();.br QWidgetListIt it( *list ); // iterate over the widgets.br QWidget * w;.br while ( (w=it.current()) != 0 ) { // for each top level widget....br ++it;.br if ( !w->isVisible() ).br w->show();.br }.br delete list; // delete the list, not the widgets.br.fi.PP\fBWarning:\fR Delete the list as soon you have finished using it. The widgets in the list may be deleted by someone else at any time..PPSee also allWidgets(), QWidget::isTopLevel, QWidget::visible and QPtrList::isEmpty()..SH "QString QApplication::translate ( const char * context, const char * sourceText, const char * comment = 0, Encoding encoding = DefaultCodec ) const"Returns the translation text for \fIsourceText\fR, by querying the installed messages files. The message files are searched from the most recently installed message file back to the first installed message file..PPQObject::tr() and QObject::trUtf8() provide this functionality more conveniently..PP\fIcontext\fR is typically a class name (e.g., "MyDialog") and \fIsourceText\fR is either English text or a short marker text, if the output text will be very long (as for help texts)..PP\fIcomment\fR is a disambiguating comment, for when the same \fIsourceText\fR is used in different roles within one context. By default, it is null..PPSee the QTranslator documentation for more information about contexts and comments..PPIf none of the message files contain a translation for \fIsourceText\fR in \fIcontext\fR, this function returns a QString equivalent of \fIsourceText\fR. The encoding of \fIsourceText\fR is specified by \fIencoding\fR; it defaults to DefaultCodec..PPThis function is not virtual. You can use alternative translation techniques by subclassing QTranslator..PPSee also QObject::tr(), installTranslator() and defaultCodec()..SH "bool QApplication::tryLock ()"Attempts to lock the Qt library mutex. If the lock was obtained, this function returns TRUE. If another thread has locked the mutex, this function returns FALSE, instead of waiting for the lock to become available..PPThe mutex must be unlocked with unlock() before another thread can successfully lock it..PPSee also lock() and unlock(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -