QApplication

概要

虚函数

信号

静态函数

详细描述

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

PySide.QtGui.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, PySide.QtGui.QApplication handles most of the system-wide and application-wide settings.

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

PySide.QtGui.QApplication object is accessible through the PySide.QtCore.QCoreApplication.instance() function that returns a pointer equivalent to the global qApp() 指针。

PySide.QtGui.QApplication ‘s main areas of responsibility are:

由于 PySide.QtGui.QApplication object does so much initialization, it must be created before any other objects related to the user interface are created. PySide.QtGui.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.

函数组
系统设置 PySide.QtGui.QApplication.desktopSettingsAware() , PySide.QtGui.QApplication.setDesktopSettingsAware() , PySide.QtGui.QApplication.cursorFlashTime() , PySide.QtGui.QApplication.setCursorFlashTime() , PySide.QtGui.QApplication.doubleClickInterval() , PySide.QtGui.QApplication.setDoubleClickInterval() , PySide.QtGui.QApplication.setKeyboardInputInterval() , PySide.QtGui.QApplication.wheelScrollLines() , PySide.QtGui.QApplication.setWheelScrollLines() , PySide.QtGui.QApplication.palette() , PySide.QtGui.QApplication.setPalette() , PySide.QtGui.QApplication.font() , PySide.QtGui.QApplication.setFont() , PySide.QtGui.QApplication.fontMetrics() . PySide.QtGui.QApplication.desktopSettingsAware() , PySide.QtGui.QApplication.setDesktopSettingsAware() , PySide.QtGui.QApplication.cursorFlashTime() , PySide.QtGui.QApplication.setCursorFlashTime() , PySide.QtGui.QApplication.doubleClickInterval() , PySide.QtGui.QApplication.setDoubleClickInterval() , PySide.QtGui.QApplication.setKeyboardInputInterval() , PySide.QtGui.QApplication.wheelScrollLines() , PySide.QtGui.QApplication.setWheelScrollLines() , PySide.QtGui.QApplication.palette() , PySide.QtGui.QApplication.setPalette() , PySide.QtGui.QApplication.font() , PySide.QtGui.QApplication.setFont() , PySide.QtGui.QApplication.fontMetrics() .
事件处理 exec() , PySide.QtCore.QCoreApplication.processEvents() , PySide.QtCore.QCoreApplication.exit() , PySide.QtCore.QCoreApplication.quit() . PySide.QtCore.QCoreApplication.sendEvent() , PySide.QtCore.QCoreApplication.postEvent() , PySide.QtCore.QCoreApplication.sendPostedEvents() , PySide.QtCore.QCoreApplication.removePostedEvents() , PySide.QtCore.QCoreApplication.hasPendingEvents() , PySide.QtGui.QApplication.notify() , macEventFilter() , qwsEventFilter() , x11EventFilter() , x11ProcessEvent() , winEventFilter() . exec() , PySide.QtCore.QCoreApplication.processEvents() , PySide.QtCore.QCoreApplication.exit() , PySide.QtCore.QCoreApplication.quit() . PySide.QtCore.QCoreApplication.sendEvent() , PySide.QtCore.QCoreApplication.postEvent() , PySide.QtCore.QCoreApplication.sendPostedEvents() , PySide.QtCore.QCoreApplication.removePostedEvents() , PySide.QtCore.QCoreApplication.hasPendingEvents() , PySide.QtGui.QApplication.notify() , macEventFilter() , qwsEventFilter() , x11EventFilter() , x11ProcessEvent() , winEventFilter() .
GUI 样式 PySide.QtGui.QApplication.style() , PySide.QtGui.QApplication.setStyle() . PySide.QtGui.QApplication.style() , PySide.QtGui.QApplication.setStyle() .
颜色用法 PySide.QtGui.QApplication.colorSpec() , PySide.QtGui.QApplication.setColorSpec() , qwsSetCustomColors() . PySide.QtGui.QApplication.colorSpec() , PySide.QtGui.QApplication.setColorSpec() , qwsSetCustomColors() .
文本处理 PySide.QtCore.QCoreApplication.installTranslator() , PySide.QtCore.QCoreApplication.removeTranslator() PySide.QtCore.QCoreApplication.translate() . PySide.QtCore.QCoreApplication.installTranslator() , PySide.QtCore.QCoreApplication.removeTranslator() PySide.QtCore.QCoreApplication.translate() .
Widgets PySide.QtGui.QApplication.allWidgets() , PySide.QtGui.QApplication.topLevelWidgets() , PySide.QtGui.QApplication.desktop() , PySide.QtGui.QApplication.activePopupWidget() , PySide.QtGui.QApplication.activeModalWidget() , PySide.QtGui.QApplication.clipboard() , PySide.QtGui.QApplication.focusWidget() , PySide.QtGui.QApplication.activeWindow() , PySide.QtGui.QApplication.widgetAt() . PySide.QtGui.QApplication.allWidgets() , PySide.QtGui.QApplication.topLevelWidgets() , PySide.QtGui.QApplication.desktop() , PySide.QtGui.QApplication.activePopupWidget() , PySide.QtGui.QApplication.activeModalWidget() , PySide.QtGui.QApplication.clipboard() , PySide.QtGui.QApplication.focusWidget() , PySide.QtGui.QApplication.activeWindow() , PySide.QtGui.QApplication.widgetAt() .
高级光标处理 PySide.QtGui.QApplication.overrideCursor() , PySide.QtGui.QApplication.setOverrideCursor() , PySide.QtGui.QApplication.restoreOverrideCursor() . PySide.QtGui.QApplication.overrideCursor() , PySide.QtGui.QApplication.setOverrideCursor() , PySide.QtGui.QApplication.restoreOverrideCursor() .
X 窗口系统同步 flushX() , PySide.QtGui.QApplication.syncX() . flushX() , PySide.QtGui.QApplication.syncX() .
会话管理 PySide.QtGui.QApplication.isSessionRestored() , PySide.QtGui.QApplication.sessionId() , PySide.QtGui.QApplication.commitData() , PySide.QtGui.QApplication.saveState() . PySide.QtGui.QApplication.isSessionRestored() , PySide.QtGui.QApplication.sessionId() , PySide.QtGui.QApplication.commitData() , PySide.QtGui.QApplication.saveState() .
杂项 PySide.QtGui.QApplication.closeAllWindows() , PySide.QtCore.QCoreApplication.startingUp() , PySide.QtCore.QCoreApplication.closingDown() , PySide.QtGui.QApplication.type() . PySide.QtGui.QApplication.closeAllWindows() , PySide.QtCore.QCoreApplication.startingUp() , PySide.QtCore.QCoreApplication.closingDown() , PySide.QtGui.QApplication.type() .
class PySide.QtGui. QApplication ( arg__1 )
class PySide.QtGui. QApplication ( arg__1 , arg__2 )
class PySide.QtGui. QApplication ( arg__1 , arg__2 )
参数:
PySide.QtGui.QApplication. Type
常量 描述
QApplication.Tty a console application
QApplication.GuiClient a GUI client application
QApplication.GuiServer a GUI server application (for Qt for Embedded Linux)
PySide.QtGui.QApplication. ColorSpec
常量 描述
QApplication.NormalColor the default color allocation policy
QApplication.CustomColor the same as NormalColor for X11; allocates colors to a palette on demand under Windows
QApplication.ManyColor the right choice for applications that use thousands of colors

PySide.QtGui.QApplication.setColorSpec() for full details.

static PySide.QtGui.QApplication. 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() .

static PySide.QtGui.QApplication. activeModalWidget ( )
返回类型: PySide.QtGui.QWidget

Returns the active modal widget.

A modal widget is a special top-level widget which is a subclass of PySide.QtGui.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.

static PySide.QtGui.QApplication. activePopupWidget ( )
返回类型: PySide.QtGui.QWidget

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 PySide.QtGui.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.

static PySide.QtGui.QApplication. activeWindow ( )
返回类型: PySide.QtGui.QWidget

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 PySide.QtGui.QApplication.activeWindow() even if there is no PySide.QtGui.QApplication.focusWidget() , for example if no widget in that window accepts key events.

static PySide.QtGui.QApplication. alert ( widget [ , duration=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.

static PySide.QtGui.QApplication. allWidgets ( )
返回类型:

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

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

注意

某些 Widget 可能被隐藏。

范例:

def updateAllWidgets():
    for widget in QApplication.allWidgets()
        widget.update()
										
PySide.QtGui.QApplication. autoSipEnabled ( )
返回类型: PySide.QtCore.bool

This property holds toggles automatic SIP (software input panel) visibility.

把此特性设为 true to automatically display the SIP when entering widgets that accept keyboard input. This property only affects widgets with the WA_InputMethodEnabled attribute set, and is typically used to launch a virtual keyboard on devices which have very few or no keys.

The property only has an effect on platforms which use software input panels, such as Windows CE and Symbian.

The default is platform dependent.

static PySide.QtGui.QApplication. beep ( )

响铃声,使用默认音量和声音。函数 not 可用于 Qt for Embedded Linux。

static PySide.QtGui.QApplication. changeOverrideCursor ( arg__1 )
参数: arg__1 PySide.QtGui.QCursor

Changes the currently active application override cursor to cursor .

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

static PySide.QtGui.QApplication. clipboard ( )
返回类型: PySide.QtGui.QClipboard

Returns a pointer to the application global clipboard.

注意

PySide.QtGui.QApplication object should already be constructed before accessing the clipboard.

static PySide.QtGui.QApplication. 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 = QAction(tr("E&xit"), self)
exitAct.setShortcut(tr("Ctrl+Q")")
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 PySide.QtGui.QApplication.quitOnLastWindowClosed() 为 false。

static PySide.QtGui.QApplication. colorSpec ( )
返回类型: PySide.QtCore.int

Returns the color specification.

PySide.QtGui.QApplication. commitData ( sm )
参数: sm PySide.QtGui.QSessionManager

This function deals with 会话管理 . It is invoked when the PySide.QtGui.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.

PySide.QtGui.QApplication. commitDataRequest ( sessionManager )
参数: sessionManager PySide.QtGui.QSessionManager
static PySide.QtGui.QApplication. cursorFlashTime ( )
返回类型: PySide.QtCore.int

This property holds the text cursor's flash (blink) time in milliseconds.

The flash time is the time required to display, invert and restore the caret display. Usually the text cursor is displayed for half the cursor flash time, then hidden for the same amount of time, but this may vary.

The default value on X11 is 1000 milliseconds. On Windows, the Control Panel value is used and setting this property sets the cursor flash time for all applications.

We recommend that widgets do not cache this value as it may change at any time if the user changes the global desktop settings.

static PySide.QtGui.QApplication. desktop ( )
返回类型: PySide.QtGui.QDesktopWidget

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

桌面可能由多个屏幕组成,因此它将是不正确的,例如:试图 center some widget in the desktop's geometry. PySide.QtGui.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.

static PySide.QtGui.QApplication. desktopSettingsAware ( )
返回类型: PySide.QtCore.bool

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

static PySide.QtGui.QApplication. doubleClickInterval ( )
返回类型: PySide.QtCore.int

This property holds the time limit in milliseconds that distinguishes a double click from two consecutive mouse clicks.

The default value on X11 is 400 milliseconds. On Windows and Mac OS, the operating system's value is used. However, on Windows and Symbian OS, calling this function sets the double click interval for all applications.

PySide.QtGui.QApplication. focusChanged ( old , now )
参数:
static PySide.QtGui.QApplication. focusWidget ( )
返回类型: PySide.QtGui.QWidget

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

static PySide.QtGui.QApplication. font ( className )
参数: className – str
返回类型: PySide.QtGui.QFont

这是重载函数。

返回 Widget 字体为给定 className .

static PySide.QtGui.QApplication. font ( arg__1 )
参数: arg__1 PySide.QtGui.QWidget
返回类型: PySide.QtGui.QFont

这是重载函数。

返回默认字体,为 widget .

static PySide.QtGui.QApplication. font ( )
返回类型: PySide.QtGui.QFont

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

PySide.QtGui.QApplication. fontDatabaseChanged ( )
static PySide.QtGui.QApplication. fontMetrics ( )
返回类型: PySide.QtGui.QFontMetrics

返回用于应用程序字体的显示 (屏幕) 字体规格。

static PySide.QtGui.QApplication. globalStrut ( )
返回类型: PySide.QtCore.QSize

This property holds the minimum size 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. The strut size should be considered when reimplementing GUI controls that may be used on touch-screens or similar I/O devices.

范例:

class MyWidget (QWidget):
    # ...
    def sizeHint(self):
        return QSize(80, 25).expandedTo(QApplication.globalStrut())
											

默认情况下,此特性包含 PySide.QtCore.QSize object with zero width and height.

PySide.QtGui.QApplication. inputContext ( )
返回类型: PySide.QtGui.QInputContext

返回 PySide.QtGui.QInputContext instance used by the application.

static PySide.QtGui.QApplication. isEffectEnabled ( arg__1 )
参数: arg__1 PySide.QtCore.Qt.UIEffect
返回类型: PySide.QtCore.bool
static PySide.QtGui.QApplication. isLeftToRight ( )
返回类型: PySide.QtCore.bool

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

static PySide.QtGui.QApplication. isRightToLeft ( )
返回类型: PySide.QtCore.bool

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

PySide.QtGui.QApplication. isSessionRestored ( )
返回类型: PySide.QtCore.bool

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

static PySide.QtGui.QApplication. keyboardInputDirection ( )
返回类型: PySide.QtCore.Qt.LayoutDirection

Returns the current keyboard input direction.

static PySide.QtGui.QApplication. keyboardInputInterval ( )
返回类型: PySide.QtCore.int

This property holds the time limit in milliseconds that distinguishes a key press from two consecutive key presses.

在 X11 默认值为 400 毫秒。在Windows 和 Mac OS 使用操作系统的值。

static PySide.QtGui.QApplication. keyboardInputLocale ( )
返回类型: PySide.QtCore.QLocale

Returns the current keyboard input locale.

static PySide.QtGui.QApplication. keyboardModifiers ( )
返回类型: PySide.QtCore.Qt.KeyboardModifiers

返回键盘修饰符键的当前状态。当前状态会被同步更新,当事件队列中的自发改变键盘状态的事件被清空时 ( QEvent.KeyPress and QEvent.KeyRelease 事件)。

应注意,这可能不反映调用时在输入设备上保持的实际键,而反映上述事件之一最后报告的修饰符。若没有被保持的键, Qt.NoModifier 被返回。

PySide.QtGui.QApplication. lastWindowClosed ( )
static PySide.QtGui.QApplication. layoutDirection ( )
返回类型: PySide.QtCore.Qt.LayoutDirection

This property holds the default layout direction for this application.

当系统启动时,默认布局方向从属应用程序的语言。

static PySide.QtGui.QApplication. mouseButtons ( )
返回类型: PySide.QtCore.Qt.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 被返回。

static PySide.QtGui.QApplication. overrideCursor ( )
返回类型: PySide.QtGui.QCursor

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

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

static PySide.QtGui.QApplication. palette ( arg__1 )
参数: arg__1 PySide.QtGui.QWidget
返回类型: PySide.QtGui.QPalette

这是重载函数。

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.

static PySide.QtGui.QApplication. palette ( className )
参数: className – str
返回类型: PySide.QtGui.QPalette

这是重载函数。

Returns the palette for widgets of the given className .

static PySide.QtGui.QApplication. palette ( )
返回类型: PySide.QtGui.QPalette

Returns the application palette.

static PySide.QtGui.QApplication. queryKeyboardModifiers ( )
返回类型: PySide.QtCore.Qt.KeyboardModifiers

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

它不依赖由此进程已接收的键按下事件,譬如:这使得当移动窗口时校验修饰符成为可能。注意:在大多数情况下,应使用 PySide.QtGui.QApplication.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.

static PySide.QtGui.QApplication. quitOnLastWindowClosed ( )
返回类型: PySide.QtCore.bool

This property holds whether the application implicitly quits when the last window is closed..

默认为 true。

If this property is true, the applications quits when the last visible primary window (i.e. window with no parent) with the Qt.WA_QuitOnClose attribute set is closed. By default this attribute is set for all widgets except for sub-windows. Refer to Qt.WindowType for a detailed list of Qt.Window 对象。

另请参阅

PySide.QtCore.QCoreApplication.quit() QWidget.close()

static PySide.QtGui.QApplication. restoreOverrideCursor ( )

撤消最后 PySide.QtGui.QApplication.setOverrideCursor() .

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

PySide.QtGui.QApplication. saveState ( sm )
参数: sm PySide.QtGui.QSessionManager

This function deals with 会话管理 . It is invoked when the session manager 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() 了解细节。

PySide.QtGui.QApplication. saveStateRequest ( sessionManager )
参数: sessionManager PySide.QtGui.QSessionManager
PySide.QtGui.QApplication. sessionId ( )
返回类型: unicode

返回当前 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 application.

PySide.QtGui.QApplication. sessionKey ( )
返回类型: unicode

返回会话键,在当前 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 PySide.QtGui.QApplication.commitData() or PySide.QtGui.QApplication.saveState() .

static PySide.QtGui.QApplication. setActiveWindow ( act )
参数: act PySide.QtGui.QWidget

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 PySide.QtGui.QApplication.activeWindow() and PySide.QtGui.QApplication.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.

PySide.QtGui.QApplication. setAutoSipEnabled ( enabled )
参数: enabled PySide.QtCore.bool

This property holds toggles automatic SIP (software input panel) visibility.

把此特性设为 true to automatically display the SIP when entering widgets that accept keyboard input. This property only affects widgets with the WA_InputMethodEnabled attribute set, and is typically used to launch a virtual keyboard on devices which have very few or no keys.

The property only has an effect on platforms which use software input panels, such as Windows CE and Symbian.

The default is platform dependent.

static PySide.QtGui.QApplication. setColorSpec ( arg__1 )
参数: arg__1 PySide.QtCore.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 PySide.QtGui.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.

范例:

def main():
    QApplication.setColorSpec(QApplication.ManyColor)
    QApplication app(sys.argv)
    ...
    return app.exec_()
										
static PySide.QtGui.QApplication. setCursorFlashTime ( arg__1 )
参数: arg__1 PySide.QtCore.int

This property holds the text cursor's flash (blink) time in milliseconds.

The flash time is the time required to display, invert and restore the caret display. Usually the text cursor is displayed for half the cursor flash time, then hidden for the same amount of time, but this may vary.

The default value on X11 is 1000 milliseconds. On Windows, the Control Panel value is used and setting this property sets the cursor flash time for all applications.

We recommend that widgets do not cache this value as it may change at any time if the user changes the global desktop settings.

static PySide.QtGui.QApplication. setDesktopSettingsAware ( arg__1 )
参数: arg__1 PySide.QtCore.bool

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

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

if __name__ == '__main__':
    QApplication.setDesktopSettingsAware(False)
    app = QApplication(sys.argv)
    # ...
    return app.exec_()
											
static PySide.QtGui.QApplication. setDoubleClickInterval ( arg__1 )
参数: arg__1 PySide.QtCore.int

This property holds the time limit in milliseconds that distinguishes a double click from two consecutive mouse clicks.

The default value on X11 is 400 milliseconds. On Windows and Mac OS, the operating system's value is used. However, on Windows and Symbian OS, calling this function sets the double click interval for all applications.

static PySide.QtGui.QApplication. setEffectEnabled ( arg__1 [ , enable=true ] )
参数:
  • arg__1 PySide.QtCore.Qt.UIEffect
  • enable PySide.QtCore.bool
static PySide.QtGui.QApplication. setFont ( arg__1 [ , className=0 ] )
参数:

把默认应用程序字体改为 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 PySide.QtGui.QApplication.styleSheet() as ” PySide.QtGui.QPushButton { font: bold }”

static PySide.QtGui.QApplication. setGlobalStrut ( arg__1 )
参数: arg__1 PySide.QtCore.QSize

This property holds the minimum size 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. The strut size should be considered when reimplementing GUI controls that may be used on touch-screens or similar I/O devices.

范例:

class MyWidget (QWidget):
    # ...
    def sizeHint(self):
        return QSize(80, 25).expandedTo(QApplication.globalStrut())
											

默认情况下,此特性包含 PySide.QtCore.QSize object with zero width and height.

static PySide.QtGui.QApplication. setGraphicsSystem ( arg__1 )
参数: arg__1 – unicode

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 PySide.QtGui.QApplication constructor is called.

注意

"opengl" option is currently experimental.

PySide.QtGui.QApplication. setInputContext ( arg__1 )
参数: arg__1 PySide.QtGui.QInputContext

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

Qt takes ownership of the given inputContext .

static PySide.QtGui.QApplication. setKeyboardInputInterval ( arg__1 )
参数: arg__1 PySide.QtCore.int

This property holds the time limit in milliseconds that distinguishes a key press from two consecutive key presses.

在 X11 默认值为 400 毫秒。在Windows 和 Mac OS 使用操作系统的值。

static PySide.QtGui.QApplication. setLayoutDirection ( direction )
参数: direction PySide.QtCore.Qt.LayoutDirection

This property holds the default layout direction for this application.

当系统启动时,默认布局方向从属应用程序的语言。

static PySide.QtGui.QApplication. setOverrideCursor ( arg__1 )
参数: arg__1 PySide.QtGui.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 PySide.QtGui.QApplication.restoreOverrideCursor() or another PySide.QtGui.QApplication.setOverrideCursor() 被调用。

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

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

范例:

QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
calculateHugeMandelbrot()              # lunch time...
QApplication.restoreOverrideCursor()
											
static PySide.QtGui.QApplication. setPalette ( arg__1 [ , className=0 ] )
参数:

Changes the default application palette to palette .

className is passed, the change applies only to widgets that inherit className (as reported by QObject.inherits() )。若 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.

static PySide.QtGui.QApplication. setQuitOnLastWindowClosed ( quit )
参数: quit PySide.QtCore.bool

This property holds whether the application implicitly quits when the last window is closed..

默认为 true。

If this property is true, the applications quits when the last visible primary window (i.e. window with no parent) with the Qt.WA_QuitOnClose attribute set is closed. By default this attribute is set for all widgets except for sub-windows. Refer to Qt.WindowType for a detailed list of Qt.Window 对象。

另请参阅

PySide.QtCore.QCoreApplication.quit() QWidget.close()

static PySide.QtGui.QApplication. setStartDragDistance ( l )
参数: l PySide.QtCore.int

If you support drag and drop in your application, and want to start a drag and drop operation after the user has moved the cursor a certain distance with a button held down, you should use this property's value as the minimum distance required.

For example, if the mouse position of the click is stored in startPos and the current position (e.g. in the mouse move event) is currentPos , you can find out if a drag should be started with code like this:

if (startPos - currentPos).manhattanLength() >= QApplication.startDragDistance():
    startTheDrag()
											

Qt 使用此值在内部,如在 PySide.QtGui.QFileDialog .

The default value is 4 pixels.

另请参阅

PySide.QtGui.QApplication.startDragTime() QPoint.manhattanLength() 拖放

static PySide.QtGui.QApplication. setStartDragTime ( ms )
参数: ms PySide.QtCore.int

This property holds the time in milliseconds that a mouse button must be held down before a drag and drop operation will begin.

If you support drag and drop in your application, and want to start a drag and drop operation after the user has held down a mouse button for a certain amount of time, you should use this property's value as the delay.

Qt also uses this delay internally, e.g. in PySide.QtGui.QTextEdit and PySide.QtGui.QLineEdit , for starting a drag.

默认值为 500 毫秒。

static PySide.QtGui.QApplication. setStyle ( arg__1 )
参数: arg__1 – unicode
返回类型: PySide.QtGui.QStyle

这是重载函数。

Requests a PySide.QtGui.QStyle 对象为 style PySide.QtGui.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 PySide.QtGui.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 PySide.QtGui.QApplication constructor, if possible.

static PySide.QtGui.QApplication. setStyle ( arg__1 )
参数: arg__1 PySide.QtGui.QStyle

Sets the application's GUI style to style . Ownership of the style object is transferred to PySide.QtGui.QApplication ,因此 PySide.QtGui.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(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 PySide.QtGui.QApplication , will cause the application to use QStyle.standardPalette() for the palette.

警告

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

PySide.QtGui.QApplication. setStyleSheet ( sheet )
参数: sheet – unicode

This property holds the application style sheet.

By default, this property returns an empty string unless the user specifies the -stylesheet option on the command line when running the application.

另请参阅

QWidget.setStyle() Qt 样式表

static PySide.QtGui.QApplication. setWheelScrollLines ( arg__1 )
参数: arg__1 PySide.QtCore.int

This property holds the number of lines to scroll a widget, when the mouse wheel is rotated..

If the value exceeds the widget's number of visible lines, the widget should interpret the scroll operation as a single page up or page down . If the widget is an item view class , then the result of scrolling one line depends on the setting of the widget's scroll mode . Scroll one line can mean scroll one item or scroll one pixel .

By default, this property has a value of 3.

static PySide.QtGui.QApplication. setWindowIcon ( icon )
参数: icon PySide.QtGui.QIcon

This property holds the default window icon.

另请参阅

QWidget.setWindowIcon() 设置应用程序图标

static PySide.QtGui.QApplication. startDragDistance ( )
返回类型: PySide.QtCore.int

If you support drag and drop in your application, and want to start a drag and drop operation after the user has moved the cursor a certain distance with a button held down, you should use this property's value as the minimum distance required.

For example, if the mouse position of the click is stored in startPos and the current position (e.g. in the mouse move event) is currentPos , you can find out if a drag should be started with code like this:

if (startPos - currentPos).manhattanLength() >= QApplication.startDragDistance():
    startTheDrag()
											

Qt 使用此值在内部,如在 PySide.QtGui.QFileDialog .

The default value is 4 pixels.

另请参阅

PySide.QtGui.QApplication.startDragTime() QPoint.manhattanLength() 拖放

static PySide.QtGui.QApplication. startDragTime ( )
返回类型: PySide.QtCore.int

This property holds the time in milliseconds that a mouse button must be held down before a drag and drop operation will begin.

If you support drag and drop in your application, and want to start a drag and drop operation after the user has held down a mouse button for a certain amount of time, you should use this property's value as the delay.

Qt also uses this delay internally, e.g. in PySide.QtGui.QTextEdit and PySide.QtGui.QLineEdit , for starting a drag.

默认值为 500 毫秒。

static PySide.QtGui.QApplication. style ( )
返回类型: PySide.QtGui.QStyle

PySide.QtGui.QApplication. styleSheet ( )
返回类型: unicode

This property holds the application style sheet.

By default, this property returns an empty string unless the user specifies the -stylesheet option on the command line when running the application.

另请参阅

QWidget.setStyle() Qt 样式表

static PySide.QtGui.QApplication. syncX ( )

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

static PySide.QtGui.QApplication. topLevelAt ( x , y )
参数:
  • x PySide.QtCore.int
  • y PySide.QtCore.int
返回类型:

PySide.QtGui.QWidget

这是重载函数。

返回的顶层 Widget 在 point ( x , y );返回 0 若没有这种 Widget。

static PySide.QtGui.QApplication. topLevelAt ( p )
参数: p PySide.QtCore.QPoint
返回类型: PySide.QtGui.QWidget

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

static PySide.QtGui.QApplication. topLevelWidgets ( )
返回类型:

返回应用程序顶层 Widget (窗口) 的列表。

注意

某些顶层 Widget 可能被隐藏,例如:工具提示,若目前未展示工具提示。

范例:

def showAllHiddenTopLevelWidgets():
    for widget in QApplication.topLevelWidgets():
        if widget.isHidden():
            widget.show()
											
static PySide.QtGui.QApplication. type ( )
返回类型: PySide.QtGui.QApplication.Type

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

static PySide.QtGui.QApplication. wheelScrollLines ( )
返回类型: PySide.QtCore.int

This property holds the number of lines to scroll a widget, when the mouse wheel is rotated..

If the value exceeds the widget's number of visible lines, the widget should interpret the scroll operation as a single page up or page down . If the widget is an item view class , then the result of scrolling one line depends on the setting of the widget's scroll mode . Scroll one line can mean scroll one item or scroll one pixel .

By default, this property has a value of 3.

static PySide.QtGui.QApplication. widgetAt ( x , y )
参数:
  • x PySide.QtCore.int
  • y PySide.QtCore.int
返回类型:

PySide.QtGui.QWidget

这是重载函数。

返回 Widget,在全局屏幕位置 ( x , y ), or 0 if there is no Qt widget there.

static PySide.QtGui.QApplication. widgetAt ( p )
参数: p PySide.QtCore.QPoint
返回类型: PySide.QtGui.QWidget

返回 Widget,在全局屏幕位置 point , or 0 if there is no Qt widget there.

此函数可能很慢。

static PySide.QtGui.QApplication. windowIcon ( )
返回类型: PySide.QtGui.QIcon

This property holds the default window icon.

另请参阅

QWidget.setWindowIcon() 设置应用程序图标