qapplication.3qt

来自「qt-x11-free-3.0.3.tar.gz minigui图形界面工具」· 3QT 代码 · 共 1,507 行 · 第 1/5 页

3QT
1,507
字号
.PPThe color specification must be set before you create the QApplication object..PPThe options are:.TPQApplication::NormalColor. This is the default color allocation strategy. Use this option if your application uses buttons, menus, texts and pixmaps with few colors. With this option, 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..TPQApplication::CustomColor. Use this option if your application needs a small number of custom colors. On X11, this option is the same as NormalColor. On Windows, Qt creates a Windows palette, and allocates colors to it on demand..TPQApplication::ManyColor. Use this option if your application is very color hungry (e.g. it requires 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"<sup>*</sup>, 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 with 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 attractive..PPExample:.PP.nf.br  int main( int argc, char **argv ).br  {.br      QApplication::setColorSpec( QApplication::ManyColor );.br      QApplication a( argc, argv );.br      ....br  }.br.fi.PPQColor provides more functionality for controlling color allocation and freeing up certain colors. See QColor::enterAllocContext() for more information..PPTo check what mode you end up with, call QColor::numBitPlanes() once the QApplication object exists. A value greater than 8 (typically 16, 24 or 32) means true color..PP<sup>*</sup> The color cube used by Qt has 216 colors whose red, green, and blue components always have one of the following values: 0x00, 0x33, 0x66, 0x99, 0xCC, or 0xFF..PPSee also colorSpec(), QColor::numBitPlanes() and QColor::enterAllocContext()..PPExamples:.)l helpviewer/main.cpp, showimg/main.cpp, t9/main.cpp, tetrix/tetrix.cpp and themes/main.cpp..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 )"Sets the default codec of the application to \fIcodec\fR..PPIf 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 the main() function might look like this:.PP.nf.br    int main(int argc, char** argv).br    {.br        QApplication app(argc, argv);.br        ... install any additional codecs ....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. If \fIinformWidgets\fR is FALSE, 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 depending on both the window system version and the locale. This function lets you override the default font; but overriding may be a bad idea because, 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, 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 biff/main.cpp, canvas/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. If \fIinformWidgets\fR is FALSE, 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's 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 application's style object..PPSee also setStyle() and QStyle..SH "void QApplication::syncX 

⌨️ 快捷键说明

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