QApplication 类

The QApplication 类管理 GUI 应用程序的控制流和主要设置。 更多...

头: #include <QApplication>
继承: QCoreApplication

公共类型

enum ColorSpec { NormalColor, CustomColor, ManyColor }
typedef QS60MainApplicationFactory
enum Type { Tty, GuiClient, GuiServer }

特性

公共函数

QApplication (int & argc , char ** argv )
QApplication (int & argc , char ** argv , bool GUIenabled )
QApplication (int & argc , char ** argv , Type type )
QApplication (Display * display , Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0)
QApplication (Display * display , int & argc , char ** argv , Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0)
QApplication (QApplication::QS60MainApplicationFactory factory , int & argc , char ** argv )
virtual ~QApplication ()
virtual void commitData (QSessionManager & manager )
QInputContext * inputContext () const
bool isSessionRestored () const
virtual bool macEventFilter (EventHandlerCallRef caller , EventRef event )
virtual bool qwsEventFilter (QWSEvent * event )
void qwsSetCustomColors (QRgb * colorTable , int start , int numColors )
virtual void saveState (QSessionManager & manager )
QString sessionId () const
QString sessionKey () const
void setInputContext (QInputContext * inputContext )
QString styleSheet () const
virtual bool symbianEventFilter (const QSymbianEvent * event )
int symbianProcessEvent (const QSymbianEvent * event )
virtual bool x11EventFilter (XEvent * event )
int x11ProcessEvent (XEvent * event )

重实现公共函数

virtual bool notify (QObject * receiver , QEvent * e )

公共槽

void aboutQt ()
int autoMaximizeThreshold () const
bool autoSipEnabled () const
void closeAllWindows ()
void setAutoMaximizeThreshold (const int threshold )
void setAutoSipEnabled (const bool enabled )
void setStyleSheet (const QString & sheet )

信号

void aboutToReleaseGpuResources ()
void aboutToUseGpuResources ()
void commitDataRequest (QSessionManager & manager )
void focusChanged (QWidget * old , QWidget * now )
void fontDatabaseChanged ()
void lastWindowClosed ()
void saveStateRequest (QSessionManager & manager )

静态公共成员

QWidget * activeModalWidget ()
QWidget * activePopupWidget ()
QWidget * activeWindow ()
void alert (QWidget * widget , int msec = 0)
QWidgetList allWidgets ()
void beep ()
void changeOverrideCursor (const QCursor & cursor )
QClipboard * clipboard ()
int colorSpec ()
int cursorFlashTime ()
QDesktopWidget * desktop ()
bool desktopSettingsAware ()
int doubleClickInterval ()
int exec ()
QWidget * focusWidget ()
QFont font ()
QFont font (const QWidget * widget )
QFont font (const char * className )
QFontMetrics fontMetrics ()
QSize globalStrut ()
bool isEffectEnabled (Qt::UIEffect effect )
bool isLeftToRight ()
bool isRightToLeft ()
Qt::LayoutDirection keyboardInputDirection ()
int keyboardInputInterval ()
QLocale keyboardInputLocale ()
Qt::KeyboardModifiers keyboardModifiers ()
Qt::LayoutDirection layoutDirection ()
Qt::MouseButtons mouseButtons ()
Qt::NavigationMode navigationMode ()
QCursor * overrideCursor ()
QPalette palette ()
QPalette palette (const QWidget * widget )
QPalette palette (const char * className )
Qt::KeyboardModifiers queryKeyboardModifiers ()
bool quitOnLastWindowClosed ()
QDecoration & qwsDecoration ()
void qwsSetDecoration (QDecoration * decoration )
QDecoration * qwsSetDecoration (const QString & decoration )
void restoreOverrideCursor ()
void setActiveWindow (QWidget * active )
void setColorSpec (int spec )
void setCursorFlashTime (int)
void setDesktopSettingsAware (bool on )
void setDoubleClickInterval (int)
void setEffectEnabled (Qt::UIEffect effect , bool enable = true)
void setFont (const QFont & font , const char * className = 0)
void setGlobalStrut (const QSize &)
void setGraphicsSystem (const QString & system )
void setKeyboardInputInterval (int)
void setLayoutDirection (Qt::LayoutDirection direction )
void setNavigationMode (Qt::NavigationMode mode )
void setOverrideCursor (const QCursor & cursor )
void setPalette (const QPalette & palette , const char * className = 0)
void setQuitOnLastWindowClosed (bool quit )
void setStartDragDistance (int l )
void setStartDragTime (int ms )
void setStyle (QStyle * style )
QStyle * setStyle (const QString & style )
void setWheelScrollLines (int)
void setWindowIcon (const QIcon & icon )
int startDragDistance ()
int startDragTime ()
QStyle * style ()
void syncX ()
QWidget * topLevelAt (const QPoint & point )
QWidget * topLevelAt (int x , int y )
QWidgetList topLevelWidgets ()
类型 type ()
int wheelScrollLines ()
QWidget * widgetAt (const QPoint & point )
QWidget * widgetAt (int x , int y )
QIcon windowIcon ()

重实现保护函数

virtual bool event (QEvent * e )

qApp

详细描述

The QApplication 类管理 GUI 应用程序的控制流和主要设置。

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 处理大多数系统范围和应用程序范围的设置。

对于使用 QT 的任何 GUI 应用程序,准确存在 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 代替,因为它不从属 QtGui 库。

The QApplication 对象可访问透过 instance () 函数返回指针相当于全局 qApp 指针。

QApplication 主要负责的领域:

  • 它采用用户的桌面设置初始化应用程序,譬如 palette (), font () 和 doubleClickInterval ()。它保持对这些特性的追踪,若用户全局更改桌面,例如透过某种控制面板。
  • 它履行事件处理,意味着它接收来自底层窗口系统的事件并将它们分派给相关 Widget。通过使用 sendEvent () 和 postEvent () 可以将自己的事件发送给 Widget。
  • 它剖析常见命令行自变量从而设置其内部状态。见 构造函数文档编制 下文了解更多细节。
  • 它定义应用程序的外观和感觉,封装在 QStyle 对象。这可以改变在运行时采用 setStyle ().
  • It specifies how the application is to allocate colors. See setColorSpec () 了解细节。
  • 它提供用户可见的字符串本地化凭借 translate ().
  • 它提供某些魔法对象,像 desktop () 和 clipboard ().
  • 它知道有关应用程序的窗口。可以询问在某个位置是哪个 Widget 使用 widgetAt (),获取列表为 topLevelWidgets () 和 closeAllWindows (),等。
  • 它管理应用程序的鼠标光标处理,见 setOverrideCursor ()
  • On the X window system, it provides functions to flush and sync the communication stream, see flushX () 和 syncX ().
  • 它提供支持完备 会话管理 。这使应用程序能够在用户注销时优雅终止,若不可能终止,可以取消关闭进程,甚至保留整个应用程序的状态对于将来的会话。见 isSessionRestored (), sessionId () 和 commitData () 和 saveState () 了解细节。

由于 QApplication 对象会做如此多的初始化,它 must 被创建,在创建用户界面相关的任何其它对象之前。 QApplication 还处理常见命令行自变量。因此,创建它通常是一个好主意 before 任何解释或修改对于 argv 的履行在应用程序本身。

函数组
系统设置 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 ().
小部件 allWidgets (), topLevelWidgets (), desktop (), activePopupWidget (), activeModalWidget (), clipboard (), focusWidget (), activeWindow (), widgetAt ().
高级光标处理 overrideCursor (), setOverrideCursor (), restoreOverrideCursor ().
X 窗口系统同步 flushX (), syncX ().
会话管理 isSessionRestored (), sessionId (), commitData (), saveState ().
杂项 closeAllWindows (), startingUp (), closingDown (), type ().

另请参阅 QCoreApplication , QAbstractEventDispatcher , QEventLoop ,和 QSettings .

成员类型文档编制

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

typedef QApplication:: QS60MainApplicationFactory

这是采用以下签名的函数指针的 typedef:

CApaApplication *myApplicationFactory();
					

This typedef was introduced in Qt 4.6.

另请参阅 QApplication::QApplication ().

enum 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)

特性文档编制

autoMaximizeThreshold : int

This property defines a threshold for auto maximizing widgets.

The auto maximize threshold is only available as part of Qt for Windows CE.

This property defines a threshold for the size of a window as a percentage of the screen size. If the minimum size hint of a window exceeds the threshold, calling show() will cause the window to be maximized automatically.

Setting the threshold to 100 or greater means that the widget will always be maximized. Alternatively, setting the threshold to 50 means that the widget will be maximized only if the vertical minimum size hint is at least 50% of the vertical screen size.

Setting the threshold to -1 disables the feature.

On Windows CE the default is -1 (i.e., it is disabled). On Windows Mobile the default is 40.

该特性在 Qt 4.4 引入。

访问函数:

int autoMaximizeThreshold () const
void setAutoMaximizeThreshold (const int threshold )

autoSipEnabled : bool

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

把此特性设为 true 以自动显示 SIP 当整个 Widget 接受键盘输入时。此特性仅影响有设置 WA_InputMethodEnabled 属性的 Widget,且通常用于在拥有很少键 (或没有键) 的设备中发起虚拟键盘。

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

默认从属平台。

该特性在 Qt 4.5 引入。

访问函数:

bool autoSipEnabled () const
void setAutoSipEnabled (const bool enabled )

cursorFlashTime : int

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

闪烁时间是显示、反转和还原插入符号显示要求的时间。通常,文本光标的显示为光标闪烁时间的一半,接着隐藏为相同时间数,但这可能有所不同。

在 X11,默认值为 1000 毫秒。在 Windows, 控制面板 值被使用且设置此特性将设置所有应用程序的光标闪烁时间。

推荐 Widget 不要缓存此值,因为它可能随时更改,若用户更改全局桌面设置。

访问函数:

int cursorFlashTime ()
void setCursorFlashTime (int)

doubleClickInterval : int

此特性保持区分双击和 2 次连续鼠标点击的时间限制 (以毫秒为单位)。

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.

访问函数:

int doubleClickInterval ()
void setDoubleClickInterval (int)

globalStrut : QSize

This property holds the minimum size that any GUI element that the user can interact with should have.

例如,不应将按钮大小重置成小于全局结构大小。应考虑结构大小,当重实现可以用于触摸屏 (或类似 I/O 设备) 的 GUI 控件时。

范例:

QSize MyWidget::sizeHint() const
{
    return QSize(80, 25).expandedTo(QApplication::globalStrut());
}
					

默认情况下,此特性包含 QSize 对象具有 0 宽度和高度。

访问函数:

QSize globalStrut ()
void setGlobalStrut (const QSize &)

keyboardInputInterval : int

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

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

该特性在 Qt 4.2 引入。

访问函数:

int keyboardInputInterval ()
void setKeyboardInputInterval (int)

layoutDirection : Qt::LayoutDirection

This property holds the default layout direction for this application.

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

访问函数:

Qt::LayoutDirection layoutDirection ()
void setLayoutDirection (Qt::LayoutDirection direction )

另请参阅 QWidget::layoutDirection , isLeftToRight (),和 isRightToLeft ().

quitOnLastWindowClosed : bool

此特性保持应用程序是否隐式离开,当关闭最后一个窗口时。

默认为 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 对象。

访问函数:

bool quitOnLastWindowClosed ()
void setQuitOnLastWindowClosed (bool quit )

另请参阅 quit () 和 QWidget::close ().

startDragDistance : int

若应用程序支持拖放,且想要开始拖放操作在用户有按下按钮将光标移动一定距离后,应使用此特性值作为最小要求距离。

例如,若将点击鼠标位置存储在 startPos 且当前位置 (如:在鼠标移动事件中) 为 currentPos , 可以找出是否应采用像这样的代码启动拖拽:

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

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

The default value is 4 pixels.

访问函数:

int startDragDistance ()
void setStartDragDistance (int l )

另请参阅 startDragTime (), QPoint::manhattanLength (),和 拖放 .

startDragTime : int

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

若应用程序支持拖放,且想要开始拖放操作在用户有按下鼠标按钮一定时间后,应使用此特性值作为延迟。

Qt 内部也使用此延迟,如在 QTextEdit and QLineEdit ,为开始拖拽。

默认值为 500 毫秒。

访问函数:

int startDragTime ()
void setStartDragTime (int ms )

另请参阅 startDragDistance () 和 拖放 .

styleSheet : QString

This property holds the application style sheet.

默认情况下,此特性返回空字符串除非用户指定 -stylesheet 选项在命令行当运行应用程序时。

该特性在 Qt 4.2 引入。

访问函数:

QString styleSheet () const
void setStyleSheet (const QString & sheet )

另请参阅 QWidget::setStyle () 和 Qt 样式表 .

wheelScrollLines : int

此特性保持 Widget 要卷动的行数,当鼠标滚轮旋转时。

若值超过 Widget 可见行数,Widget 应将卷动操作解释成单 page up or page down 。若 Widget 是 项视图类 ,那么导致卷动一 line 从属小部件的设置 卷动模式 。卷动一 line 可以意味着 卷动 1 项 or 卷动 1 像素 .

默认情况下,此属性拥有 3 值。

访问函数:

int wheelScrollLines ()
void setWheelScrollLines (int)

windowIcon : QIcon

This property holds the default window icon.

访问函数:

QIcon windowIcon ()
void setWindowIcon (const QIcon & icon )

另请参阅 QWidget::setWindowIcon () 和 设置应用程序图标 .

成员函数文档编制

QApplication:: QApplication ( int & argc , char ** argv )

初始化窗口系统并构造应用程序对象采用 argc 命令行自变量在 argv .

警告: 数据引用通过 argc and argv 必须保持有效对于整个生命周期 QApplication 对象。此外, argc 必须大于 0 且 argv 必须包含至少一条有效字符串。

全局 qApp 指针引用此应用程序对象。只应创建一个应用程序对象。

此应用程序对象必须被构造先于任何 描绘设备 (包括小部件、像素图、位图等)。

注意: argc and argv 可能改变当 Qt 移除它识别的命令行自变量时。

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

  • -nograb, tells Qt that it must never grab the mouse or the keyboard.
  • -dograb (only under X11), running under a debugger can cause an implicit -nograb, use -dograb to override.
  • -sync (only under X11), switches to synchronous mode for debugging.

调试技术 for a more detailed explanation.

所有 Qt 程序自动支持以下命令行选项:

  • -style= style , sets the application GUI style. Possible values are motif , windows ,和 platinum . If you compiled Qt with additional styles or have additional styles as plugins these will be available to the -style 命令行选项。
  • -style style ,与上文列出的相同。
  • -stylesheet= stylesheet ,设置应用程序 styleSheet 。值必须是包含样式表的文件路径。

    注意: 样式表文件中的相对 URL 相对于样式表文件路径。

  • -stylesheet stylesheet ,与上文列出的相同。
  • -session= session ,还原应用程序从早期 session .
  • -session session ,与上文列出的相同。
  • -widgetcount,结束时打印调试信息 (剩余未销毁的 Widget 大约数量和同时存在的 Widget 最大数量)
  • -reverse,将应用程序的布局方向设为 Qt::RightToLeft
  • -graphicssystem, sets the backend to be used for on-screen widgets and QPixmaps. Available options are raster and opengl .
  • -qmljsdebugger=,采用指定端口激活 QML/JS 调试器。值格式必须为 port:1234[,block],其中 block 可选且使应用程序等待,直到调试器连接到它为止。

The X11 version of Qt supports some traditional X11 command line options:

  • -display display , sets the X display (default is $DISPLAY).
  • -geometry geometry , sets the client geometry of the first window that is shown.
  • -fn or -font font , defines the application font. The font should be specified using an X logical font description. Note that this option is ignored when Qt is built with fontconfig support enabled.
  • -bg or -background color , sets the default background color and an application palette (light and dark shades are calculated).
  • -fg or -foreground color , sets the default foreground color.
  • -btn or -button color , sets the default button color.
  • -name name , sets the application name.
  • -title title , sets the application title.
  • -visual TrueColor , forces the application to use a TrueColor visual on an 8-bit display.
  • -ncols count , limits the number of colors allocated in the color cube on an 8-bit display, if the application is using the QApplication::ManyColor color specification. If count is 216 then a 6x6x6 color cube is used (i.e. 6 levels of red, 6 of green, and 6 of blue); for other values, a cube approximately proportional to a 2x3x1 cube is used.
  • -cmap, causes the application to install a private color map on an 8-bit display.
  • -im, sets the input method server (equivalent to setting the XMODIFIERS environment variable)
  • -inputstyle, defines how the input is inserted into the given widget, e.g., onTheSpot makes the input appear directly in the widget, while overTheSpot makes the input appear in a box floating over the widget and is not inserted until the editing is done.

X11 Notes

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

另请参阅 arguments ().

QApplication:: QApplication ( int & argc , char ** argv , bool GUIenabled )

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

警告: 数据引用通过 argc and argv 必须保持有效对于整个生命周期 QApplication 对象。此外, argc 必须大于 0 且 argv 必须包含至少一条有效字符串。

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 为 true。若 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:: QApplication ( int & argc , char ** argv , Type type )

Constructs an application object with argc 命令行自变量在 argv .

警告: 数据引用通过 argc and argv 必须保持有效对于整个生命周期 QApplication 对象。此外, argc 必须大于 0 且 argv 必须包含至少一条有效字符串。

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

QApplication:: QApplication ( 显示 * display , Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0)

Creates an application, given an already open display display 。若 visual and colormap are non-zero, the application will use those values as the default Visual and Colormap contexts.

警告: Qt only supports TrueColor visuals at depths higher than 8 bits-per-pixel.

This function is only available on X11.

QApplication:: QApplication ( 显示 * display , int & argc , char ** argv , Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0)

Creates an application, given an already open display and using argc 命令行自变量在 argv 。若 visual and colormap are non-zero, the application will use those values as the default Visual and Colormap contexts.

警告: Qt only supports TrueColor visuals at depths higher than 8 bits-per-pixel.

This function is only available on X11.

QApplication:: QApplication ( QApplication::QS60MainApplicationFactory factory , int & argc , char ** argv )

Creates an application using the application factory given in factory , and using argc 命令行自变量在 argv . factory can be leaving, but the error will be converted to a standard exception.

This function is only available on S60.

该函数在 Qt 4.6 引入。

[虚拟] QApplication:: ~QApplication ()

清理由此应用程序分配的任何窗口系统资源。设置全局变量 qApp 为 0。

[static slot] void QApplication:: aboutQt ()

显示关于 Qt 的简单消息框。消息包括应用程序正使用的 Qt 版本号。

这很有用,对于包括 帮助 菜单的应用程序,如展示在 菜单 范例。

此函数是方便槽对于 QMessageBox::aboutQt ().

[signal] void QApplication:: aboutToReleaseGpuResources ()

This signal is emitted when application is about to release all GPU resources associated to contexts owned by application.

The signal is particularly useful if your application has allocated GPU resources directly apart from Qt and needs to do some last-second cleanup.

警告: This signal is only emitted on Symbian.

This function was introduced in Qt 4.7.4.

另请参阅 aboutToUseGpuResources ().

[signal] void QApplication:: aboutToUseGpuResources ()

This signal is emitted when application is about to use GPU resources.

The signal is particularly useful if your application needs to know when GPU resources are be available.

警告: This signal is only emitted on Symbian.

This function was introduced in Qt 4.7.4.

另请参阅 aboutToReleaseGpuResources ().

[static] QWidget * QApplication:: activeModalWidget ()

返回活动的模态 Widget。

模态 Widget 是特殊顶层 Widget 是子类化的 QDialog 将构造函数的模态参数指定为 true。必须关闭模态 Widget 在用户可以继续程序的其它部分之前。

模态 Widget 被组织在堆栈中。此函数返回堆栈顶部的活动模态 Widget。

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

[static] QWidget * QApplication:: activePopupWidget ()

返回活动弹出 Widget。

弹出 Widget 是特殊顶层 Widget 有设置 Qt::WType_Popup 小部件标志,如 QMenu 小部件。当应用程序打开弹出 Widget 时,所有事件会被发送给弹出 Widget。正常 Widget 和模态 Widget 无法访问,在关闭弹出 Widget 之前。

只能打开其它弹出 Widget,当展示弹出 Widget 时。弹出 Widget 被组织在堆栈中。此函数返回在堆栈顶部的活动弹出 Widget。

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

[static] QWidget * QApplication:: activeWindow ()

返回拥有键盘输入聚焦的应用程序顶层窗口,或 0 若没有应用程序窗口拥有聚焦。可能有 activeWindow() 即使没有 focusWidget (),例如:若该窗口的 Widget 不接受键事件。

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

[static] void QApplication:: alert ( QWidget * widget , int msec = 0)

导致展示警报 widget 若窗口不是活动窗口。展示警报 msec 毫秒。若 msec 为 0 (默认),则无限期展示警报,直到窗口再次变为活动为止。

目前,此函数在 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.

在 Windows,这导致窗口的任务栏条目会闪烁一段时间。若 msec 为 0,闪烁会停止,且任务栏条目将变成不同颜色 (目前为橙色)。

在 X11,这导致窗口会被标记成 "要求关注",窗口不得隐藏 (即:没有对它调用 hide(),但以某种方式可见) 为让这能工作。

该函数在 Qt 4.3 引入。

[static] QWidgetList QApplication:: allWidgets ()

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

列表是空的 ( QList::isEmpty ()) 若没有 Widget。

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

范例:

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

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

[static] void QApplication:: beep ()

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

[static] void QApplication:: changeOverrideCursor (const QCursor & cursor )

将当前活动应用程序的覆盖光标改为 cursor .

此函数不起作用若 setOverrideCursor () 未被调用。

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

[static] QClipboard * QApplication:: clipboard ()

Returns a pointer to the application global clipboard.

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

[static slot] void QApplication:: closeAllWindows ()

关闭所有顶层窗口。

此函数尤其有用,对于具有很多顶层窗口的应用程序而言。例如,可以将它连接到 Exit 条目在 File 菜单:

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

窗口按随机次序关闭,直到某个窗口不接受关闭事件为止。应用程序离开,当成功关闭最后一个窗口时;可以关闭这通过设置 quitOnLastWindowClosed 为 false。

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

[static] int QApplication:: colorSpec ()

Returns the color specification.

另请参阅 QApplication::setColorSpec ().

[虚拟] void QApplication:: commitData ( QSessionManager & manager )

This function deals with 会话管理 。它被援引当 QSessionManager 想要应用程序提交其所有数据。

通常这意味着保存所有打开文件,在从用户获得权限后。此外,可能想要提供由用户可以取消关闭的手段。

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 要求 manager 明确权限。见 QSessionManager::allowsInteraction () 和 QSessionManager::allowsErrorInteraction () 了解细节和范例用法。

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 (),和 会话管理 .

[signal] void QApplication:: commitDataRequest ( QSessionManager & manager )

此信号处理 会话管理 。它被发射当 QSessionManager 想要应用程序提交其所有数据。

通常这意味着保存所有打开文件,在从用户获得权限后。此外,可能想要提供由用户可以取消关闭的手段。

不应退出应用程序,在此信号内。相反,会话管理器可以 (或不可以) 之后这样做,从属上下文。

警告: 在此信号内,不可能进行用户交互, unless 要求 manager 明确权限。见 QSessionManager::allowsInteraction () 和 QSessionManager::allowsErrorInteraction () 了解细节和范例用法。

注意: 应使用 Qt::DirectConnection 当连接到此信号时。

该函数在 Qt 4.2 引入。

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

[static] QDesktopWidget * QApplication:: desktop ()

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

桌面可能由多个屏幕组成,因此它将是不正确的,例如:试图 center 某个 Widget 在桌面几何体中。 QDesktopWidget 拥有各种用于获得桌面上有用几何体的函数,譬如 QDesktopWidget::screenGeometry () 和 QDesktopWidget::availableGeometry ().

在 X11,在桌面上绘制也是可能的。

[static] 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 ().

[virtual protected] bool QApplication:: event ( QEvent * e )

重实现自 QObject::event ().

[static] int QApplication:: exec ()

进入主事件循环并等待,直到 exit () 被调用,然后将设置值返回给 exit () (为 0 若 exit () 被调用凭借 quit ()).

有必要调用此函数以启动事件处理。主事件循环从窗口系统接收事件,并将其分派给应用程序 Widget。

一般来说,在调用 exec() 之前不会发生用户交互。作为特殊情况,模态 Widget 像 QMessageBox 可以在调用 exec() 之前使用,因为模态 Widget 会调用 exec() 以启动本地事件循环。

要使应用程序履行空闲处理 (即:执行特殊函数,每当没有待决事件时),使用 QTimer 采用 0 超时。更高级空闲处理方案可以达成使用 processEvents ().

推荐把清理代码连接到 aboutToQuit() 信号,而不是将它放入应用程序的 main() 函数。这是因为,在某些平台调用 QApplication::exec() 可能不返回。例如,在 Windows 平台,当用户注销时,系统会在 Qt 关闭所有顶层窗口后终止进程。因此, 不保证 应用程序会有时间退出其事件循环并执行代码结束 main() 函数,在调用 QApplication::exec() 后。

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

[signal] void QApplication:: focusChanged ( QWidget * old , QWidget * now )

此信号被发射当 Widget 键盘聚焦的改变是从 old to now ,即,由于用户按下 tab 键、点击 Widget,或改变活动窗口。两者 old and now 可以是 null 指针。

信号被发射后于 2 小部件被通知即将改变透过 QFocusEvent .

该函数在 Qt 4.1 引入。

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

[static] QWidget * QApplication:: focusWidget ()

返回拥有键盘输入聚焦的应用程序 Widget,或 0 若此应用程序的 Widget 不拥有聚焦。

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

[static] QFont QApplication:: font ()

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

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

[static] QFont QApplication:: font (const QWidget * widget )

这是重载函数。

返回默认字体,为 widget .

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

[static] QFont QApplication:: font (const char * className )

这是重载函数。

返回 Widget 字体为给定 className .

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

[signal] void QApplication:: fontDatabaseChanged ()

此信号被发射当应用程序字体被加载或移除时。

该函数在 Qt 4.5 引入。

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

[static] QFontMetrics QApplication:: fontMetrics ()

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

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

QInputContext * QApplication:: inputContext () const

返回 QInputContext instance used by the application.

另请参阅 setInputContext ().

[static] bool QApplication:: isEffectEnabled ( Qt::UIEffect effect )

返回 true 若 effect is enabled; otherwise returns false.

默认情况下,Qt 试着使用桌面设置。要阻止这,调用 setDesktopSettingsAware (false).

注意: 所有效果被禁用,当运行在低于 16 位颜色深度的屏幕。

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

[static] bool QApplication:: isLeftToRight ()

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

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

[static] bool QApplication:: isRightToLeft ()

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

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

bool QApplication:: isSessionRestored () const

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

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

[static] Qt::LayoutDirection QApplication:: keyboardInputDirection ()

Returns the current keyboard input direction.

该函数在 Qt 4.2 引入。

[static] QLocale QApplication:: keyboardInputLocale ()

Returns the current keyboard input locale.

该函数在 Qt 4.2 引入。

[static] Qt::KeyboardModifiers QApplication:: keyboardModifiers ()

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

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

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

[signal] void QApplication:: lastWindowClosed ()

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

默认情况下,

  • this attribute is set for all widgets except transient windows such as splash screens, tool windows, and popup menus
  • QApplication implicitly quits when this signal is emitted.

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

另请参阅 QWidget::close ().

[虚拟] bool QApplication:: macEventFilter ( EventHandlerCallRef caller , EventRef event )

警告: This virtual function is only used under Mac OS X, and behaves different depending on if Qt is based on Carbon or Cocoa.

For the Carbon port, If you create an application that inherits QApplication and reimplement this function, you get direct access to all Carbon Events that Qt registers for from Mac OS X with this function being called with the caller event .

For the Cocoa port, If you create an application that inherits QApplication and reimplement this function, you get direct access to all Cocoa Events that Qt receives from Mac OS X with this function being called with the caller being 0 and the event being an NSEvent pointer:

NSEvent *e = reinterpret_cast<NSEvent *>(event);

Return true if you want to stop the event from being processed. Return false for normal event dispatching. The default implementation returns false.

[static] Qt::MouseButtons QApplication:: mouseButtons ()

返回鼠标按钮的当前状态。当前状态是同步更新的,因为事件队列会清空自发改变鼠标状态的事件 ( QEvent::MouseButtonPress and QEvent::MouseButtonRelease 事件)。

应该注意的是,这可能不反映调用时输入设备保持的实际按钮,而是某一上述事件最后报告的鼠标按钮。若未按住鼠标按钮 Qt::NoButton 被返回。

另请参阅 keyboardModifiers ().

返回 Qt 使用哪种聚焦导航。

This feature is available in Qt for Embedded Linux, Symbian and Windows CE only.

注意: On Windows CE this feature is disabled by default for touch device mkspecs. To enable keypad navigation, build Qt with QT_KEYPAD_NAVIGATION defined.

注意: On Symbian, the default mode is Qt::NavigationModeNone for touch devices, and Qt::NavigationModeKeypadDirectional .

该函数在 Qt 4.6 引入。

另请参阅 setNavigationMode () 和 keypadNavigationEnabled ().

[虚拟] bool QApplication:: notify ( QObject * receiver , QEvent * e )

重实现自 QCoreApplication::notify ().

[static] QCursor * QApplication:: overrideCursor ()

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

此函数返回 0 若应用程序光标未定义 (即:内部光标堆栈为空)。

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

[static] QPalette QApplication:: palette ()

Returns the application palette.

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

[static] QPalette QApplication:: palette (const QWidget * widget )

这是重载函数。

widget 有传递,返回 Widget 类的默认调色板。这可能 (或不可能) 是应用程序调色板。在大多数情况下,某些类型的 Widget 没有特殊调色板,但值得注意的一例外是 Windows 下的弹出菜单,若用户有为显示菜单,设置定义了特殊背景颜色。

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

[static] QPalette QApplication:: palette (const char * className )

这是重载函数。

返回用于 Widget 的调色板为给定 className .

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

[static] Qt::KeyboardModifiers QApplication:: queryKeyboardModifiers ()

查询并返回键盘修饰符键的状态。不像 keyboardModifiers 此方法返回调用方法时保持在输入设备上的实际键。

它不依赖必须由此进程接收的键按下事件,譬如:这使得当移动窗口时校验修饰符成为可能。注意:在大多数情况下,应使用 keyboardModifiers (),其更快更准确,因为它包含的修饰符状态 (如同接收当前处理事件时状态)。

该函数在 Qt 4.8 引入。

另请参阅 keyboardModifiers ().

[static] QDecoration & QApplication:: qwsDecoration ()

Return the QWSDecoration used for decorating windows.

警告: This method is non-portable. It is only available in Qt for Embedded Linux.

另请参阅 QDecoration .

[虚拟] bool QApplication:: qwsEventFilter ( QWSEvent * event )

This virtual function is only implemented under Qt for Embedded Linux.

If you create an application that inherits QApplication and reimplement this function, you get direct access to all QWS (Q Window System) events that the are received from the QWS master process. The events are passed in the event 参数。

Return true if you want to stop the event from being processed. Return false for normal event dispatching. The default implementation returns false.

void QApplication:: qwsSetCustomColors ( QRgb * colorTable , int start , int numColors )

Set Qt for Embedded Linux custom color table.

Qt for Embedded Linux on 8-bpp displays allocates a standard 216 color cube. The remaining 40 colors may be used by setting a custom color table in the QWS master process before any clients connect.

colorTable is an array of up to 40 custom colors. start is the starting index (0-39) and numColors is the number of colors to be set (1-40).

This method is non-portable. It is available only in Qt for Embedded Linux.

注意: The custom colors will not be used by the default screen driver. To make use of the new colors, implement a custom screen driver, or use QDirectPainter .

[static] void QApplication:: qwsSetDecoration ( QDecoration * decoration )

设置 QDecoration derived class to use for decorating the windows used by Qt for Embedded Linux to the decoration 指定。

This method is non-portable. It is only available in Qt for Embedded Linux.

另请参阅 QDecoration .

[static] QDecoration * QApplication:: qwsSetDecoration (const QString & decoration )

这是重载函数。

请求 QDecoration 对象为 decoration QDecorationFactory .

字符串必须是某一 QDecorationFactory::keys (). Keys are case insensitive.

A later call to the QApplication constructor will override the requested style when a "-style" option is passed in as a commandline parameter.

返回 0 若未知 decoration 被传递,否则 QStyle 返回对象被设为应用程序的 GUI 样式。

[static] void QApplication:: restoreOverrideCursor ()

撤消最后 setOverrideCursor ().

setOverrideCursor () 被调用 2 次,调用 restoreOverrideCursor() 将激活第 1 次光标设置。第 2 次调用此函数将还原 Widget 的原始光标。

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

[虚拟] void QApplication:: saveState ( QSessionManager & manager )

This function deals with 会话管理 。它被援引当 会话管理器 想要应用程序为未来会话保留其状态。

例如,文本编辑器将创建临时文件 (包括当前编辑缓冲内容、光标位置及当前编辑会话的其它方面)。

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 要求 manager 明确权限。见 QSessionManager::allowsInteraction () 和 QSessionManager::allowsErrorInteraction () 了解细节。

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

[signal] void QApplication:: saveStateRequest ( QSessionManager & manager )

此信号处理 会话管理 。它被援引当 会话管理器 想要应用程序为未来会话保留其状态。

例如,文本编辑器将创建临时文件 (包括当前编辑缓冲内容、光标位置及当前编辑会话的其它方面)。

从不应该在此信号内退出应用程序。相反,会话管理器可以 (或不可以) 在之后履行此,从属上下文。更进一步,大多数会话管理器很可能会立即请求保存状态 (在应用程序启动后)。这准许会话管理器了解应用程序的重启策略。

警告: Within this function, no user interaction is possible, unless 要求 manager 明确权限。见 QSessionManager::allowsInteraction () 和 QSessionManager::allowsErrorInteraction () 了解细节。

注意: 应使用 Qt::DirectConnection 当连接到此信号时。

该函数在 Qt 4.2 引入。

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

QString QApplication:: sessionId () const

返回当前 会话的 标识符。

若应用程序已从早期会话还原,此标识符与先前会话标识符相同。会话标识符保证,对于不同应用程序和同一应用程序的不同实例是唯一的。

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

QString QApplication:: sessionKey () const

返回会话键,在当前 session .

若应用程序已从早期会话还原,此键与先前会话结束时的键相同。

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

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

[static] void QApplication:: setActiveWindow ( QWidget * active )

将活动窗口设为 active 小部件以响应系统事件。函数调用自平台特定事件处理程序。

警告: 此函数做 not 设置活动 Widget 的键盘聚焦。调用 QWidget::activateWindow () 代替。

它设置 activeWindow () 和 focusWidget () 属性并发送适当 WindowActivate / WindowDeactivate and FocusIn / FocusOut 事件到所有合适 Widget。然后,将按活动状态描绘窗口 (如:行编辑中的光标会眨眼),且它将启用工具提示。

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

[static] void QApplication:: setColorSpec ( int spec )

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:

  • QApplication::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 the Windows platform, it may cause dithering of non-standard colors.
  • QApplication::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.
  • QApplication::ManyColor . Use this option if your application is very color hungry, e.g., it requires thousands of colors.
    Under X11 the effect is:
    • For 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" (the red, green, and blue components always have one of the following values: 0x00, 0x33, 0x66, 0x99, 0xCC, or 0xFF), but the number of colors can be changed by the -ncols option. The user can force the application to use the true color visual with the -visual 选项。
    • For 256-color displays which have a true color visual with more than 256 colors, use that visual. Silicon Graphics X servers 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.

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 ().

[static] void QApplication:: setDesktopSettingsAware ( bool on )

将 Qt 是否应使用系统标准颜色、字体等设为 on . By default, this is true.

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

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

另请参阅 desktopSettingsAware ().

[static] void QApplication:: setEffectEnabled ( Qt::UIEffect effect , bool enable = true)

启用 UI 效果 effect if enable 为 True,否则效果将不会被使用。

注意: 所有效果被禁用,当运行在低于 16 位颜色深度的屏幕。

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

[static] void QApplication:: setFont (const QFont & font , const char * className = 0)

将应用程序默认字体改为 font 。若 className 有传递,改变仅适用的类继承 className (如报告通过 QObject::inherits ()).

当应用程序启动时,默认字体从属窗口系统。它可能因窗口系统版本和区域设置两者而异。此函数让您覆盖默认字体;但覆盖可能是坏主意,因为,例如:某些区域设置需要特大字体以支持它们的特殊字符。

警告: 不要使用此函数结合 Qt 样式表 。可以使用 font 样式表特性定制应用程序字体。要为所有 QPushButton 设置粗体字体,设置应用程序 styleSheet () 如 " QPushButton { font: bold }"

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

[static] void QApplication:: setGraphicsSystem (const QString & system )

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:

  • the application commandline -graphicssystem switch
  • QApplication::setGraphicsSystem()
  • the QT_GRAPHICSSYSTEM environment variable
  • the Qt configure -graphicssystem switch

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.

注意: The "opengl" option is currently experimental.

该函数在 Qt 4.5 引入。

void QApplication:: setInputContext ( QInputContext * inputContext )

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

Qt takes ownership of the given inputContext .

另请参阅 inputContext ().

[static] void QApplication:: setNavigationMode ( Qt::NavigationMode mode )

将聚焦导航 Qt 应使用的种类设为 mode .

This feature is available in Qt for Embedded Linux, Symbian and Windows CE only.

注意: On Windows CE this feature is disabled by default for touch device mkspecs. To enable keypad navigation, build Qt with QT_KEYPAD_NAVIGATION defined.

注意: On Symbian, setting the mode to Qt::NavigationModeCursorAuto will enable a virtual mouse cursor on non touchscreen devices, which is controlled by the cursor keys if there is no analog pointer device. On other platforms and on touchscreen devices, it has the same meaning as Qt::NavigationModeNone .

该函数在 Qt 4.6 引入。

另请参阅 navigationMode () 和 keypadNavigationEnabled ().

[static] void QApplication:: setOverrideCursor (const QCursor & cursor )

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

应用程序覆盖光标旨在向用户展示应用程序处于特殊状态,例如:在可能需要一些时间的操作期间。

此光标将显示在所有应用程序的 Widget 中,直到 restoreOverrideCursor () 或另一 setOverrideCursor() 被调用。

应用程序光标存储在内部堆栈中。setOverrideCursor() 将光标压入堆栈,而 restoreOverrideCursor () 将活动光标从堆栈中弹出。 changeOverrideCursor () 更改目前活动的应用程序覆盖光标。

每个 setOverrideCursor() 之后最终必须跟随相应 restoreOverrideCursor (),否则,将从不清空堆栈。

范例:

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

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

[static] void QApplication:: setPalette (const QPalette & palette , const char * className = 0)

将应用程序默认调色板更改为 palette .

className 有传递,改变仅应用于 Widget 有继承 className (如报告通过 QObject::inherits ())。若 className 为 0,改变影响所有 Widget,从而覆盖任何先前设置的类特定调色板。

调色板可能根据当前 GUI 风格改变在 QStyle::polish ().

警告: 不要使用此函数结合 Qt 样式表 。当使用样式表时,可以使用 color、background-color、selection-color、selection-background-color 及 alternate-background-color 定制 Widget 调色板。

注意: 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 ().

[static] void QApplication:: setStyle ( QStyle * style )

将应用程序的 GUI 风格设为 style 。将风格对象的所有权转移给 QApplication ,所以 QApplication 会在应用程序退出时删除风格对象,或者当有设置新风格且旧风格仍是应用程序对象的父级时。

用法范例:

QApplication::setStyle(new QWindowsStyle);
				

当切换应用程序风格时,颜色调色板被设回初始颜色 (或系统默认)。这有必要,由于某些风格必须适配颜色调色板,以完全兼容风格指南。

设置风格在设置调色板之前,即先于创建 QApplication ,将导致应用程序使用 QStyle::standardPalette () 对于调色板。

警告: Qt 样式表目前不支持自定义 QStyle 子类。计划在某些未来发行中解决此问题。

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

[static] QStyle * QApplication:: setStyle (const QString & style )

这是重载函数。

请求 QStyle 对象为 style QStyleFactory .

字符串必须是某一 QStyleFactory::keys (), typically one of "windows", "motif", "cde", "plastique", "windowsxp", or "macintosh". Style names are case insensitive.

返回 0 若未知 style 被传递,否则 QStyle 返回对象被设为应用程序的 GUI 样式。

警告: 要确保应用程序样式设置正确,最好调用此函数先于 QApplication 构造函数,若可能的话。

[static] QStyle * QApplication:: style ()

另请参阅 setStyle () 和 QStyle .

[虚拟] bool QApplication:: symbianEventFilter (const QSymbianEvent * event )

警告: This virtual function is only available on Symbian.

If you create an application that inherits QApplication and reimplement this function, you get direct access to events that the are received from Symbian. The events are passed in the event 参数。

Return true if you want to stop the event from being processed. Return false for normal event dispatching. The default implementation returns false, and does nothing with event .

该函数在 Qt 4.6 引入。

int QApplication:: symbianProcessEvent (const QSymbianEvent * event )

警告: This function is only available on Symbian.

This function processes an individual Symbian event event . It returns 1 if the event was handled, 0 if the event was not handled, and -1 if the event was not handled because the event is not known to Qt.

该函数在 Qt 4.6 引入。

[static] void QApplication:: syncX ()

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

[static] QWidget * QApplication:: topLevelAt (const QPoint & point )

返回顶层 Widget 按给定 point ;返回 0 若没有这种 Widget。

[static] QWidget * QApplication:: topLevelAt ( int x , int y )

这是重载函数。

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

[static] QWidgetList QApplication:: topLevelWidgets ()

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

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

范例:

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

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

[static] Type QApplication:: type ()

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

[static] QWidget * QApplication:: widgetAt (const QPoint & point )

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

此函数可能很慢。

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

[static] QWidget * QApplication:: widgetAt ( int x , int y )

这是重载函数。

返回 Widget 按全局屏幕位置 ( x , y ),或 0 若那里没有 Qt Widget。

[虚拟] bool QApplication:: x11EventFilter ( XEvent * event )

警告: This virtual function is only implemented under X11.

If you create an application that inherits QApplication and reimplement this function, you get direct access to all X events that the are received from the X server. The events are passed in the event 参数。

Return true if you want to stop the event from being processed. Return false for normal event dispatching. The default implementation returns false.

It is only the directly addressed messages that are filtered. You must install an event filter directly on the event dispatcher, which is returned by QAbstractEventDispatcher::instance (), to handle system wide messages.

另请参阅 x11ProcessEvent ().

int QApplication:: x11ProcessEvent ( XEvent * event )

This function does the core processing of individual X event s, normally by dispatching Qt events to the right destination.

It returns 1 if the event was consumed by special handling, 0 if the event was consumed by normal handling, and -1 if the event was for an unrecognized widget.

另请参阅 x11EventFilter ().

宏文档编制

qApp

A global pointer referring to the unique application object. It is equivalent to the pointer returned by the QCoreApplication::instance () function except that, in GUI applications, it is a pointer to a QApplication 实例。

Only one application object can be created.

另请参阅 QCoreApplication::instance ().