QApplication Class Reference

[ QtGui module]

The QApplication class manages the GUI application's control flow and main settings. 更多...

继承 QCoreApplication .

类型

方法

Static Methods

Qt Signals


详细描述

The QApplication class manages the GUI application's control flow and main settings.

QApplication contains the main event loop, where all events from the window system and other sources are processed and dispatched. It also handles the application's initialization, finalization, and provides session management. In addition, QApplication handles most of the system-wide and application-wide settings.

For any GUI application using Qt, there is precisely one QApplication object, no matter whether the application has 0, 1, 2 or more windows at any given time. For non-GUI Qt applications, use QCoreApplication instead, as it does not depend on the QtGui 库。

The QApplication object is accessible through the instance () function that returns a pointer equivalent to the global qApp pointer.

QApplication 的主要职责领域:

Since the QApplication object does so much initialization, it must be created before any other objects related to the user interface are created. QApplication also deals with common command line arguments. Hence, it is usually a good idea to create it before any interpretation or modification of argv is done in the application itself.

函数组
系统设置 desktopSettingsAware (), setDesktopSettingsAware (), cursorFlashTime (), setCursorFlashTime (), doubleClickInterval (), setDoubleClickInterval (), setKeyboardInputInterval (), wheelScrollLines (), setWheelScrollLines (), palette (), setPalette (), font (), setFont (), fontMetrics ().
事件处理 exec_ (), processEvents (), exit (), quit (). sendEvent (), postEvent (), sendPostedEvents (), removePostedEvents (), hasPendingEvents (), notify (), macEventFilter (), qwsEventFilter (), x11EventFilter (), x11ProcessEvent (), winEventFilter ().
GUI 样式 style (), setStyle ().
颜色用法 colorSpec (), setColorSpec (), qwsSetCustomColors ().
文本处理 installTranslator (), removeTranslator () translate ().
Widgets allWidgets (), topLevelWidgets (), desktop (), activePopupWidget (), activeModalWidget (), clipboard (), focusWidget (), activeWindow (), widgetAt ().
高级光标处理 overrideCursor (), setOverrideCursor (), restoreOverrideCursor ().
X 窗口系统同步 flushX (), syncX ().
会话管理 isSessionRestored (), sessionId (), commitData (), saveState ().
杂项 closeAllWindows (), startingUp (), closingDown (), type ().

类型文档编制

QApplication.ColorSpec

常量 描述
QApplication.NormalColor 0 the default color allocation policy
QApplication.CustomColor 1 the same as NormalColor for X11; allocates colors to a palette on demand under Windows
QApplication.ManyColor 2 the right choice for applications that use thousands of colors

setColorSpec () for full details.

QApplication.Type

常量 描述
QApplication.Tty 0 a console application
QApplication.GuiClient 1 a GUI client application
QApplication.GuiServer 2 a GUI server application (for Qt for Embedded Linux)

方法文档编制

QApplication.__init__ ( self , list-of-str  argv )

Initializes the window system and constructs an application object with argc command line arguments in argv .

警告: The data referred to by argc and argv must stay valid for the entire lifetime of the QApplication object. In addition, argc must be greater than zero and argv must contain at least one valid character string.

全局 qApp pointer refers to this application object. Only one application object should be created.

This application object must be constructed before any paint devices (including widgets, pixmaps, bitmaps etc.).

注意: argc and argv might be changed as Qt removes command line arguments that it recognizes.

Qt debugging options (not available if Qt was compiled without the QT_DEBUG flag defined):

调试技术 for a more detailed explanation.

All Qt programs automatically support the following command line 选项:

The X11 version of Qt supports some traditional X11 command line 选项:

X11 Notes

QApplication fails to open the X11 display, it will terminate the process. This behavior is consistent with most X11 applications.

另请参阅 arguments ().

QApplication.__init__ ( self , list-of-str  argv , bool  GUIenabled )

Constructs an application object with argc 命令行 arguments in argv 。若 GUIenabled is true, a GUI application is constructed, otherwise a non-GUI (console) application is created.

警告: The data referred to by argc and argv must stay valid for the entire lifetime of the QApplication object. In addition, argc must be greater than zero and argv must contain at least one valid character string.

Set GUIenabled to false for programs without a graphical user interface that should be able to run without a window system.

On X11, the window system is initialized if GUIenabled is true. If GUIenabled is false, the application does not connect to the X server. On Windows and Mac OS, currently the window system is always initialized, regardless of the value of GUIenabled. This may change in future versions of Qt.

The following example shows how to create an application that uses a graphical interface when available.

 int main(int argc, char **argv)
 {
 #ifdef Q_WS_X11
     bool useGUI = getenv("DISPLAY") != 0;
 #else
     bool useGUI = true;
 #endif
     QApplication app(argc, argv, useGUI);
     if (useGUI) {
        // start GUI version
        ...
     } else {
        // start non-GUI version
        ...
     }
     return app.exec();
 }
			

QApplication.__init__ ( self , list-of-str  argv , Type )

Constructs an application object with argc 命令行 arguments in argv .

警告: The data referred to by argc and argv must stay valid for the entire lifetime of the QApplication object. In addition, argc must be greater than zero and argv must contain at least one valid character string.

With Qt for Embedded Linux, passing QApplication.GuiServer for type makes this application the server (equivalent to running with the -qws option).

QApplication.aboutQt ()

This method is also a Qt slot with the C++ signature void aboutQt() .

Displays a simple message box about Qt. The message includes the version number of Qt being used by the application.

This is useful for inclusion in the Help menu of an application, as shown in the 菜单 范例。

This function is a convenience slot for QMessageBox.aboutQt ().

QWidget QApplication.activeModalWidget ()

Returns the active modal widget.

A modal widget is a special top-level widget which is a subclass of QDialog that specifies the modal parameter of the constructor as true. A modal widget must be closed before the user can continue with other parts of the program.

Modal widgets are organized in a stack. This function returns the active modal widget at the top of the stack.

另请参阅 activePopupWidget () 和 topLevelWidgets ().

QWidget QApplication.activePopupWidget ()

Returns the active popup widget.

A popup widget is a special top-level widget that sets the Qt.WType_Popup widget flag, e.g. the QMenu widget. When the application opens a popup widget, all events are sent to the popup. Normal widgets and modal widgets cannot be accessed before the popup widget is closed.

Only other popup widgets may be opened when a popup widget is shown. The popup widgets are organized in a stack. This function returns the active popup widget at the top of the stack.

另请参阅 activeModalWidget () 和 topLevelWidgets ().

QWidget QApplication.activeWindow ()

Returns the application top-level window that has the keyboard input focus, or 0 if no application window has the focus. There might be an activeWindow() even if there is no focusWidget (), for example if no widget in that window accepts key events.

另请参阅 setActiveWindow (), QWidget.setFocus (), QWidget.hasFocus (),和 focusWidget ().

QApplication.alert ( QWidget   widget , int  msecs  = 0)

Causes an alert to be shown for widget if the window is not the active window. The alert is shown for msec miliseconds. If msec is zero (the default), then the alert is shown indefinitely until the window becomes active again.

Currently this function does nothing on Qt for Embedded Linux.

On Mac OS X, this works more at the application level and will cause the application icon to bounce in the dock.

On Windows, this causes the window's taskbar entry to flash for a time. If msec is zero, the flashing will stop and the taskbar entry will turn a different color (currently orange).

On X11, this will cause the window to be marked as "demands attention", the window must not be hidden (i.e. not have hide() called on it, but be visible in some sort of way) in order for this to work.

该函数在 Qt 4.3 引入。

list-of-QWidget QApplication.allWidgets ()

返回应用程序的所有 Widget 的列表。

列表是空的 ( QList.isEmpty ()) if there are no widgets.

注意: 某些 Widget 可能被隐藏。

范例:

 void updateAllWidgets()
 {
     foreach (QWidget *widget, QApplication.allWidgets())
         widget->update();
 }
			

另请参阅 topLevelWidgets () 和 QWidget.isVisible ().

bool QApplication.autoSipEnabled ( self )

QApplication.beep ()

Sounds the bell, using the default volume and sound. The function is not 可用于 Qt for Embedded Linux。

QApplication.changeOverrideCursor ( QCursor )

Changes the currently active application override cursor to cursor .

此函数不起作用若 setOverrideCursor () was not called.

另请参阅 setOverrideCursor (), overrideCursor (), restoreOverrideCursor (), and QWidget.setCursor ().

QClipboard QApplication.clipboard ()

Returns a pointer to the application global clipboard.

注意: QApplication object should already be constructed before accessing the clipboard.

QApplication.closeAllWindows ()

This method is also a Qt slot with the C++ signature void closeAllWindows() .

关闭所有顶层窗口。

This function is particularly useful for applications with many top-level windows. It could, for example, be connected to a Exit entry in the File menu:

     exitAct = new QAction(tr("E&xit"), this);
     exitAct->setShortcuts(QKeySequence.Quit);
     exitAct->setStatusTip(tr("Exit the application"));
     connect(exitAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
			

The windows are closed in random order, until one window does not accept the close event. The application quits when the last window was successfully closed; this can be turned off by setting quitOnLastWindowClosed 为 false。

另请参阅 quitOnLastWindowClosed , lastWindowClosed (), QWidget.close (), QWidget.closeEvent (), lastWindowClosed (), quit (), topLevelWidgets (),和 QWidget.isWindow ().

int QApplication.colorSpec ()

Returns the color specification.

另请参阅 QApplication.setColorSpec ().

QApplication.commitData ( self , QSessionManager   sm )

This function deals with session management . It is invoked when the QSessionManager wants the application to commit all its data.

Usually this means saving all open files, after getting permission from the user. Furthermore you may want to provide a means by which the user can cancel the shutdown.

You should not exit the application within this function. Instead, the session manager may or may not do this afterwards, depending on the context.

警告: Within this function, no user interaction is possible, unless you ask the manager for explicit permission. See QSessionManager.allowsInteraction () and QSessionManager.allowsErrorInteraction () for details and example usage.

The default implementation requests interaction and sends a close event to all visible top-level widgets. If any event was rejected, the shutdown is canceled.

另请参阅 isSessionRestored (), sessionId (), saveState (),和 会话管理 .

int QApplication.cursorFlashTime ()

QDesktopWidget QApplication.desktop ()

返回桌面 Widget (也称根窗口)。

The desktop may be composed of multiple screens, so it would be incorrect, for example, to attempt to center some widget in the desktop's geometry. QDesktopWidget has various functions for obtaining useful geometries upon the desktop, such as QDesktopWidget.screenGeometry () and QDesktopWidget.availableGeometry ().

On X11, it is also possible to draw on the desktop.

bool QApplication.desktopSettingsAware ()

Returns true if Qt is set to use the system's standard colors, fonts, etc.; otherwise returns false. The default is true.

另请参阅 setDesktopSettingsAware ().

int QApplication.doubleClickInterval ()

bool QApplication.event ( self , QEvent )

重实现自 QObject.event ().

int QApplication.exec_ ()

进入主事件循环并等待,直到 exit () is called, then returns the value that was set to exit () (其为 0 若 exit () 被调用凭借 quit ()).

It is necessary to call this function to start event handling. The main event loop receives events from the window system and dispatches these to the application widgets.

Generally, no user interaction can take place before calling exec(). As a special case, modal widgets like QMessageBox can be used before calling exec(), because modal widgets call exec() to start a local event loop.

To make your application perform idle processing, i.e., executing a special function whenever there are no pending events, use a QTimer with 0 timeout. More advanced idle processing schemes can be achieved using processEvents ().

推荐把清理代码连接到 aboutToQuit() signal, instead of putting it in your application's main() function. This is because, on some platforms the QApplication.exec() call may not return. For example, on the Windows platform, when the user logs off, the system terminates the process after Qt closes all top-level windows. Hence, there is no guarantee that the application will have time to exit its event loop and execute code at the end of the main() function, after the QApplication.exec() call.

另请参阅 quitOnLastWindowClosed , quit (), exit (), processEvents (),和 QCoreApplication.exec ().

QWidget QApplication.focusWidget ()

Returns the application widget that has the keyboard input focus, or 0 if no widget in this application has the focus.

另请参阅 QWidget.setFocus (), QWidget.hasFocus (), activeWindow (),和 focusChanged ().

QFont QApplication.font ()

返回默认的应用程序字体。

另请参阅 setFont (), fontMetrics (),和 QWidget.font ().

QFont QApplication.font ( QWidget )

这是重载函数。

返回默认字体,为 widget .

另请参阅 fontMetrics () 和 QWidget.setFont ().

QFont QApplication.font (str  className )

这是重载函数。

返回 Widget 字体为给定 className .

另请参阅 setFont () 和 QWidget.font ().

QFontMetrics QApplication.fontMetrics ()

Returns display (screen) font metrics for the application font.

另请参阅 font (), setFont (), QWidget.fontMetrics (),和 QPainter.fontMetrics ().

QSize QApplication.globalStrut ()

QInputContext QApplication.inputContext ( self )

返回 QInputContext instance used by the application.

另请参阅 setInputContext ().

bool QApplication.isEffectEnabled ( Qt.UIEffect )

返回 true 若 effect 被启用;否则返回 false.

By default, Qt will try to use the desktop settings. To prevent this, call setDesktopSettingsAware(false).

注意: All effects are disabled on screens running at less than 16-bit color depth.

另请参阅 setEffectEnabled () 和 Qt.UIEffect .

bool QApplication.isLeftToRight ()

Returns true if the application's layout direction is Qt.LeftToRight ;否则 returns false.

另请参阅 layoutDirection () 和 isRightToLeft ().

bool QApplication.isRightToLeft ()

Returns true if the application's layout direction is Qt.RightToLeft ;否则 returns false.

另请参阅 layoutDirection () 和 isLeftToRight ().

bool QApplication.isSessionRestored ( self )

Returns true if the application has been restored from an earlier session ;否则返回 false.

另请参阅 sessionId (), commitData (),和 saveState ().

Qt.LayoutDirection QApplication.keyboardInputDirection ()

Returns the current keyboard input direction.

该函数在 Qt 4.2 引入。

int QApplication.keyboardInputInterval ()

QLocale QApplication.keyboardInputLocale ()

Returns the current keyboard input locale.

该函数在 Qt 4.2 引入。

Qt.KeyboardModifiers QApplication.keyboardModifiers ()

Returns the current state of the modifier keys on the keyboard. The current state is updated sychronously as the event queue is emptied of events that will spontaneously change the keyboard state ( QEvent.KeyPress and QEvent.KeyRelease 事件)。

It should be noted this may not reflect the actual keys held on the input device at the time of calling but rather the modifiers as last reported in one of the above events. If no keys are being held Qt.NoModifier is returned.

另请参阅 mouseButtons () 和 queryKeyboardModifiers ().

Qt.LayoutDirection QApplication.layoutDirection ()

Qt.MouseButtons QApplication.mouseButtons ()

Returns the current state of the buttons on the mouse. The current state is updated syncronously as the event queue is emptied of events that will spontaneously change the mouse state ( QEvent.MouseButtonPress and QEvent.MouseButtonRelease 事件)。

It should be noted this may not reflect the actual buttons held on the input device at the time of calling but rather the mouse buttons as last reported in one of the above events. If no mouse buttons are being held Qt.NoButton 被返回。

另请参阅 keyboardModifiers ().

bool QApplication.notify ( self , QObject , QEvent )

重实现自 QCoreApplication.notify ().

QCursor QApplication.overrideCursor ()

返回活动应用程序的覆盖光标。

This function returns 0 if no application cursor has been defined (i.e. the internal cursor stack is empty).

另请参阅 setOverrideCursor () 和 restoreOverrideCursor ().

QPalette QApplication.palette ()

Returns the application palette.

另请参阅 setPalette () 和 QWidget.palette ().

QPalette QApplication.palette ( QWidget )

这是重载函数。

widget is passed, the default palette for the widget's class is returned. This may or may not be the application palette. In most cases there is no special palette for certain types of widgets, but one notable exception is the popup menu under Windows, if the user has defined a special background color for menus in the display settings.

另请参阅 setPalette () 和 QWidget.palette ().

QPalette QApplication.palette (str  className )

这是重载函数。

Returns the palette for widgets of the given className .

另请参阅 setPalette () 和 QWidget.palette ().

Qt.KeyboardModifiers QApplication.queryKeyboardModifiers ()

Queries and returns the state of the modifier keys on the keyboard. Unlike keyboardModifiers, this method returns the actual keys held on the input device at the time of calling the 方法。

It does not rely on the keypress events having been received by this process, which makes it possible to check the modifiers while moving a window, for instance. Note that in most cases, you should use keyboardModifiers (), which is faster and more accurate since it contains the state of the modifiers as they were when the currently processed event was received.

该函数在 Qt 4.8 引入。

另请参阅 keyboardModifiers ().

bool QApplication.quitOnLastWindowClosed ()

QApplication.restoreOverrideCursor ()

撤消最后 setOverrideCursor ().

setOverrideCursor () has been called twice, calling restoreOverrideCursor() will activate the first cursor set. Calling this function a second time restores the original widgets' cursors.

另请参阅 setOverrideCursor () 和 overrideCursor ().

QApplication.saveState ( self , QSessionManager   sm )

This function deals with session management . It is invoked when the 会话管理器 wants the application to preserve its state for a future session.

For example, a text editor would create a temporary file that includes the current contents of its edit buffers, the location of the cursor and other aspects of the current editing session.

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.

警告: Within this function, no user interaction is possible, unless you ask the manager for explicit permission. See QSessionManager.allowsInteraction () and QSessionManager.allowsErrorInteraction () 了解细节。

另请参阅 isSessionRestored (), sessionId (), commitData (),和 会话管理 .

QString QApplication.sessionId ( self )

返回当前 session's 标识符。

If the application has been restored from an earlier session, this identifier is the same as it was in that previous session. The session identifier is guaranteed to be unique both for different applications and for different instances of the same 应用程序。

另请参阅 isSessionRestored (), sessionKey (), commitData (),和 saveState ().

QString QApplication.sessionKey ( self )

返回会话键,在当前 session .

If the application has been restored from an earlier session, this key is the same as it was when the previous session ended.

The session key changes with every call of commitData () 或 saveState ().

另请参阅 isSessionRestored (), sessionId (), commitData (),和 saveState ().

QApplication.setActiveWindow ( QWidget   act )

Sets the active window to the active widget in response to a system event. The function is called from the platform specific event handlers.

警告: This function does not set the keyboard focus to the active widget. Call QWidget.activateWindow () 代替。

It sets the activeWindow () 和 focusWidget () attributes and sends proper WindowActivate / WindowDeactivate and FocusIn / FocusOut events to all appropriate widgets. The window will then be painted in active state (e.g. cursors in line edits will blink), and it will have tool tips enabled.

另请参阅 activeWindow () 和 QWidget.activateWindow ().

QApplication.setAutoSipEnabled ( self , bool  enabled )

This method is also a Qt slot with the C++ signature void setAutoSipEnabled(const bool) .

QApplication.setColorSpec (int)

Sets the color specification for the application to spec .

The color specification controls how the application allocates colors when run on a display with a limited amount of colors, e.g. 8 bit / 256 color displays.

The color specification must be set before you create the QApplication 对象。

The options are:

Be 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.

范例:

 int main(int argc, char *argv[])
 {
     QApplication.setColorSpec(QApplication.ManyColor);
     QApplication app(argc, argv);
     ...
     return app.exec();
 }
			

另请参阅 colorSpec ().

QApplication.setCursorFlashTime (int)

QApplication.setDesktopSettingsAware (bool)

Sets whether Qt should use the system's standard colors, fonts, etc., to on . By default, this is true.

此函数必须先被调用才创建 QApplication 对象,像这样:

 int main(int argc, char *argv[])
 {
     QApplication.setDesktopSettingsAware(false);
     QApplication app(argc, argv);
     ...
     return app.exec();
 }
			

另请参阅 desktopSettingsAware ().

QApplication.setDoubleClickInterval (int)

QApplication.setEffectEnabled ( Qt.UIEffect   effect , bool  enabled  = True)

Enables the UI effect effect if enable is true, otherwise the effect will not be used.

注意: All effects are disabled on screens running at less than 16-bit color depth.

另请参阅 isEffectEnabled (), Qt.UIEffect ,和 setDesktopSettingsAware ().

QApplication.setFont ( QFont   font , str  className  = None)

把默认应用程序字体改为 font 。若 className is passed, the change applies only to classes that inherit className (as reported by QObject.inherits ()).

On 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.

警告: Do not use this function in conjunction with Qt 样式表 . The font of an application can be customized using the "font" style sheet property. To set a bold font for all QPushButtons, set the application styleSheet () as " QPushButton { font: bold }"

另请参阅 font (), fontMetrics (),和 QWidget.setFont ().

QApplication.setGlobalStrut ( QSize )

QApplication.setGraphicsSystem (QString)

Sets the default graphics backend to system , which will be used for on-screen widgets and QPixmaps. The available systems are "native" , "raster" and "opengl" .

There are several ways to set the graphics backend, in order of decreasing precedence:

If the highest precedence switch sets an invalid name, the error will be ignored and the default backend will be used.

警告: This function is only effective before the QApplication constructor is called.

注意: "opengl" option is currently experimental.

该函数在 Qt 4.5 引入。

QApplication.setInputContext ( self , QInputContext )

QInputContext argument has it's ownership transferred to Qt.

This function replaces the QInputContext instance used by the application with inputContext .

Qt takes ownership of the given inputContext .

另请参阅 inputContext ().

QApplication.setKeyboardInputInterval (int)

QApplication.setLayoutDirection ( Qt.LayoutDirection   direction )

QApplication.setOverrideCursor ( QCursor )

将应用程序覆盖光标设为 cursor .

Application 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.

This cursor will be displayed in all the application's widgets until restoreOverrideCursor () or another setOverrideCursor() is called.

Application cursors are stored on an internal stack. setOverrideCursor() pushes the cursor onto the stack, and restoreOverrideCursor () pops the active cursor off the stack. changeOverrideCursor () changes the curently active application override cursor.

Every setOverrideCursor() must eventually be followed by a corresponding restoreOverrideCursor (), otherwise the stack will never be emptied.

范例:

 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor));
 calculateHugeMandelbrot();              // lunch time...
 QApplication.restoreOverrideCursor();
			

另请参阅 overrideCursor (), restoreOverrideCursor (), changeOverrideCursor (), and QWidget.setCursor ().

QApplication.setPalette ( QPalette   palette , str  className  = None)

Changes the default application palette to palette .

className is passed, the change applies only to widgets that inherit className (as reported by QObject.inherits ()). If className is left 0, the change affects all widgets, thus overriding any previously set class specific palettes.

The palette may be changed according to the current GUI style in QStyle.polish ().

警告: Do not use this function in conjunction with Qt 样式表 . When using style sheets, the palette of a widget can be customized using the "color", "background-color", "selection-color", "selection-background-color" and "alternate-background-color".

注意: Some styles do not use the palette for all drawing, for instance, if they make use of native theme engines. This is the case for the Windows XP, Windows Vista, and Mac OS X styles.

另请参阅 QWidget.setPalette (), palette (),和 QStyle.polish ().

QApplication.setQuitOnLastWindowClosed (bool  quit )

QApplication.setStartDragDistance (int  l )

QApplication.setStartDragTime (int  ms )

QApplication.setStyle ( QStyle )

QStyle argument has it's ownership transferred to Qt.

Sets the application's GUI style to style . 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 and the old style is still the parent of the application object.

用法范例:

 QApplication.setStyle(new QWindowsStyle);
			

When 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.

Setting the style before a palette has been set, i.e., before creating QApplication , will cause the application to use QStyle.standardPalette () 为 palette.

警告: Qt style sheets are currently not supported for custom QStyle subclasses. We plan to address this in some future release.

另请参阅 style (), QStyle , setPalette (),和 desktopSettingsAware ().

QStyle QApplication.setStyle (QString)

这是重载函数。

Requests a QStyle 对象为 style QStyleFactory .

The string must be one of the QStyleFactory.keys (), typically one of "windows", "motif", "cde", "plastique", "windowsxp", or "macintosh". Style names are case insensitive.

Returns 0 if an unknown style is passed, otherwise the QStyle object returned is set as the application's GUI style.

警告: To ensure that the application's style is set correctly, it is best to call this function before the QApplication constructor, if possible.

QApplication.setStyleSheet ( self , QString  sheet )

This method is also a Qt slot with the C++ signature void setStyleSheet(const QString&) .

QApplication.setWheelScrollLines (int)

QApplication.setWindowIcon ( QIcon   icon )

int QApplication.startDragDistance ()

int QApplication.startDragTime ()

QStyle QApplication.style ()

另请参阅 setStyle () 和 QStyle .

QString QApplication.styleSheet ( self )

QApplication.syncX ()

Synchronizes with the X server in the X11 implementation. This normally takes some time. Does nothing on other platforms.

QWidget QApplication.topLevelAt ( QPoint   p )

返回的顶层 Widget 在给定 point ;返回 0 if there is no such widget.

QWidget QApplication.topLevelAt (int  x , int  y )

这是重载函数。

返回的顶层 Widget 在 point ( x , y ); returns 0 if there is no such widget.

list-of-QWidget QApplication.topLevelWidgets ()

Returns a list of the top-level widgets (windows) in the 应用程序。

注意: Some of the top-level widgets may be hidden, for example a tooltip if no tooltip is currently shown.

范例:

 void showAllHiddenTopLevelWidgets()
 {
     foreach (QWidget *widget, QApplication.topLevelWidgets()) {
         if (widget->isHidden())
             widget->show();
     }
 }
			

另请参阅 allWidgets (), QWidget.isWindow (),和 QWidget.isHidden ().

Type QApplication.type ()

Returns the type of application ( Tty , GuiClient ,或 GuiServer ). The type is set when constructing the QApplication 对象。

int QApplication.wheelScrollLines ()

QWidget QApplication.widgetAt ( QPoint   p )

返回 Widget,在全局屏幕位置 point , or 0 若那里没有 Qt Widget。

此函数可能很慢。

另请参阅 QCursor.pos (), QWidget.grabMouse (),和 QWidget.grabKeyboard ().

QWidget QApplication.widgetAt (int  x , int  y )

QIcon QApplication.windowIcon ()


Qt Signal Documentation

void commitDataRequest (QSessionManager&)

This is the default overload of this signal.

This signal deals with session management . It is emitted when the QSessionManager wants the application to commit all its data.

Usually this means saving all open files, after getting permission from the user. Furthermore you may want to provide a means by which the user can cancel the shutdown.

You should not exit the application within this signal. Instead, the session manager may or may not do this afterwards, depending on the context.

警告: Within this signal, no user interaction is possible, unless you ask the manager for explicit permission. See QSessionManager.allowsInteraction () and QSessionManager.allowsErrorInteraction () for details and example usage.

注意: 应使用 Qt.DirectConnection when connecting to this signal.

该函数在 Qt 4.2 引入。

另请参阅 isSessionRestored (), sessionId (), saveState (),和 会话管理 .

void focusChanged (QWidget*,QWidget*)

This is the default overload of this signal.

This signal is emitted when the widget that has keyboard focus changed from old to now , i.e., because the user pressed the tab-key, clicked into a widget or changed the active window. Both old and now can be the null-pointer.

The signal is emitted after both widget have been notified about the change through QFocusEvent .

该函数在 Qt 4.1 引入。

另请参阅 QWidget.setFocus (), QWidget.clearFocus (),和 Qt.FocusReason .

void fontDatabaseChanged ()

This is the default overload of this signal.

This signal is emitted when application fonts are loaded or removed.

该函数在 Qt 4.5 引入。

另请参阅 QFontDatabase.addApplicationFont (), QFontDatabase.addApplicationFontFromData (), QFontDatabase.removeAllApplicationFonts (), and QFontDatabase.removeApplicationFont ().

void lastWindowClosed ()

This is the default overload of this signal.

此信号被发射从 QApplication.exec () when the last visible primary window (i.e. window with no parent) with the Qt.WA_QuitOnClose attribute set is closed.

默认情况下,

This feature can be turned off by setting quitOnLastWindowClosed 为 false。

另请参阅 QWidget.close ().

void saveStateRequest (QSessionManager&)

This is the default overload of this signal.

This signal deals with session management . It is invoked when the 会话管理器 wants the application to preserve its state for a future session.

For example, a text editor would create a temporary file that includes the current contents of its edit buffers, the location of the cursor and other aspects of the current editing session.

You should never exit the application within this signal. 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.

警告: Within this function, no user interaction is possible, unless you ask the manager for explicit permission. See QSessionManager.allowsInteraction () and QSessionManager.allowsErrorInteraction () 了解细节。

注意: 应使用 Qt.DirectConnection when connecting to this signal.

该函数在 Qt 4.2 引入。

另请参阅 isSessionRestored (), sessionId (), commitData (),和 会话管理 .