Struct rute::auto::gui_application::GuiApplication
source · pub struct GuiApplication<'a> { /* private fields */ }
Expand description
Notice these docs are heavy WIP and not very relevent yet
QGuiApplication 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 and finalization, and provides session management. In addition, QGuiApplication handles most of the system-wide and application-wide settings.
For any GUI application using Qt, there is precisely one QGuiApplication 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 Qt GUI module. For QWidget based Qt applications, use QApplication instead, as it provides some functionality needed for creating QWidget instances.
The QGuiApplication object is accessible through the instance() function, which returns a pointer equivalent to the global qApp pointer.
QGuiApplication’s main areas of responsibility are:
- It initializes the application with the user’s desktop settings, such as palette(), font() and styleHints(). It keeps track of these properties in case the user changes the desktop globally, for example, through some kind of control panel.
- It performs event handling, meaning that it receives events from the underlying window system and dispatches them to the relevant widgets. You can send your own events to windows by using sendEvent() and postEvent().
- It parses common command line arguments and sets its internal state accordingly. See the constructor documentation below for more details.
- It provides localization of strings that are visible to the user via translate().
- It provides some magical objects like the clipboard().
- It knows about the application’s windows. You can ask which window is at a certain position using topLevelAt(), get a list of topLevelWindows(), etc.
- It manages the application’s mouse cursor handling, see setOverrideCursor()
- It provides support for sophisticated session management . This makes it possible for applications to terminate gracefully when the user logs out, to cancel a shutdown process if termination isn’t possible and even to preserve the entire application’s state for a future session. See isSessionRestored(), sessionId() and commitDataRequest() and saveStateRequest() for details.
Since the QGuiApplication object does so much initialization, it must be
created before any other objects related to the user interface are created.
QGuiApplication 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.
-
{2,1} Groups of functions
-
System settings
-
desktopSettingsAware(), setDesktopSettingsAware(), styleHints(), palette(), setPalette(), font(), setFont().
-
Event handling
-
exec(), processEvents(), exit(), quit(). sendEvent(), postEvent(), sendPostedEvents(), removePostedEvents(), hasPendingEvents(), notify().
-
Windows
-
allWindows(), topLevelWindows(), focusWindow(), clipboard(), topLevelAt().
-
Advanced cursor handling
-
overrideCursor(), setOverrideCursor(), restoreOverrideCursor().
-
Session management
-
isSessionRestored(), sessionId(), commitDataRequest(), saveStateRequest().
-
Miscellaneous
-
startingUp(), closingDown().
See also: CoreApplication
[AbstractEventDispatcher
]
[EventLoop
]
Licence
The documentation is an adoption of the original Qt Documentation and provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.
Implementations
sourceimpl<'a> GuiApplication<'a>
impl<'a> GuiApplication<'a>
pub fn set_application_display_name(name: &str)
sourcepub fn application_display_name() -> String
pub fn application_display_name() -> String
This name is shown to the user, for instance in window titles. It can be translated, if necessary.
If not set, the application display name defaults to the application name.
See also: applicationName
pub fn set_desktop_file_name(name: &str)
sourcepub fn desktop_file_name() -> String
pub fn desktop_file_name() -> String
This is the file name, without the full path, of the desktop entry that represents this application according to the freedesktop desktop entry specification.
This property gives a precise indication of what desktop entry represents the application and it is needed by the windowing system to retrieve such information without resorting to imprecise heuristics.
The latest version of the freedesktop desktop entry specification can be obtained here
sourcepub fn top_level_at<P: PointTrait<'a>>(pos: &P) -> Option<Window<'a>>
pub fn top_level_at<P: PointTrait<'a>>(pos: &P) -> Option<Window<'a>>
Returns the top level window at the given position pos, if any.
pub fn set_window_icon<I: IconTrait<'a>>(icon: &I)
sourcepub fn window_icon() -> Icon<'a>
pub fn window_icon() -> Icon<'a>
See also: Window::set_icon
{Setting the Application Icon}
sourcepub fn platform_name() -> String
pub fn platform_name() -> String
The QPA platform plugins are located in qtbase\src\plugins\platforms
.
At the time of writing, the following platform plugin names are supported:
-
android
-
cocoa
is a platform plugin for MacOS . -
directfb
-
eglfs
is a platform plugin for running Qt5 applications on top of EGL and OpenGL ES 2.0 without an actual windowing system (like X11 or Wayland). For more information, see EGLFS -
ios
(also used for tvOS) -
kms
is an experimental platform plugin using kernel modesetting and DRM (Direct Rendering Manager). -
linuxfb
writes directly to the framebuffer. For more information, see LinuxFB -
minimal
is provided as an examples for developers who want to write their own platform plugins. However, you can use the plugin to run GUI applications in environments without a GUI, such as servers. -
minimalegl
is an example plugin. -
offscreen
-
openwfd
-
qnx
-
windows
-
wayland
is a platform plugin for modern Linux desktops and some embedded systems. -
xcb
is the X11 plugin used on regular desktop Linux platforms.
For more information about the platform plugins for embedded Linux devices, see Qt for Embedded Linux
sourcepub fn modal_window() -> Option<Window<'a>>
pub fn modal_window() -> Option<Window<'a>>
Returns the most recently shown modal window. If no modal windows are visible, this function returns zero.
A modal window is a window which has its modality property set to Qt::WindowModal or Qt::ApplicationModal. A modal window must be closed before the user can continue with other parts of the program.
Modal window are organized in a stack. This function returns the modal window at the top of the stack.
See also: [t::window_modality()
]
Window::set_modality
sourcepub fn focus_window() -> Option<Window<'a>>
pub fn focus_window() -> Option<Window<'a>>
Returns the QWindow that receives events tied to focus, such as key events.
This signal is emitted when the focused window changes. focusWindow is the new focused window.
See also: [focus_window()
]
sourcepub fn focus_object() -> Option<Object<'a>>
pub fn focus_object() -> Option<Object<'a>>
This signal is emitted when final receiver of events tied to focus is changed. focusObject is the new receiver.
See also: [focus_object()
]
Returns the QObject in currently active window that will be final receiver of events tied to focus, such as key events.
sourcepub fn primary_screen() -> Option<Screen<'a>>
pub fn primary_screen() -> Option<Screen<'a>>
This will be the screen where QWindows are initially shown, unless otherwise specified.
The primaryScreenChanged signal was introduced in Qt 5.6.
See also: [screens()
]
sourcepub fn screen_at<P: PointTrait<'a>>(point: &P) -> Option<Screen<'a>>
pub fn screen_at<P: PointTrait<'a>>(point: &P) -> Option<Screen<'a>>
Returns a list of all the screens associated with the windowing system the application is connected to.
Returns the screen at point, or nullptr
if outside of any screen.
The point is in relation to the virtualGeometry() of each set of virtual siblings. If the point maps to more than one set of virtual siblings the first match is returned.
sourcepub fn device_pixel_ratio(&self) -> f32
pub fn device_pixel_ratio(&self) -> f32
Returns the highest screen device pixel ratio found on the system. This is the ratio between physical pixels and device-independent pixels.
Use this function only when you don’t know which window you are targeting. If you do know the target window, use QWindow::devicePixelRatio() instead.
See also: Window::device_pixel_ratio
sourcepub fn override_cursor() -> Option<Cursor<'a>>
pub fn override_cursor() -> Option<Cursor<'a>>
Returns the active application override cursor.
This function returns 0 if no application cursor has been defined (i.e. the internal cursor stack is empty).
See also: [set_override_cursor()
]
[restore_override_cursor()
]
sourcepub fn set_override_cursor<C: CursorTrait<'a>>(arg0: &C)
pub fn set_override_cursor<C: CursorTrait<'a>>(arg0: &C)
Sets the application override cursor to 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.
Example:
See also: [override_cursor()
]
[restore_override_cursor()
]
[change_override_cursor()
]
Widget::set_cursor
sourcepub fn change_override_cursor<C: CursorTrait<'a>>(arg0: &C)
pub fn change_override_cursor<C: CursorTrait<'a>>(arg0: &C)
Changes the currently active application override cursor to cursor.
This function has no effect if setOverrideCursor() was not called.
See also: [set_override_cursor()
]
[override_cursor()
]
[restore_override_cursor()
]
Widget::set_cursor
sourcepub fn restore_override_cursor()
pub fn restore_override_cursor()
Undoes the last setOverrideCursor().
If setOverrideCursor() has been called twice, calling restoreOverrideCursor() will activate the first cursor set. Calling this function a second time restores the original widgets’ cursors.
See also: [set_override_cursor()
]
[override_cursor()
]
sourcepub fn font() -> Font<'a>
pub fn font() -> Font<'a>
This signal is emitted when the font of the application changes.
See also: [font()
]
Returns the default application font.
See also: [set_font()
]
This signal is emitted when application fonts are loaded or removed.
See also: [FontDatabase::add_application_font
]
[FontDatabase::add_application_font_from_data
]
[FontDatabase::remove_all_application_fonts
]
[FontDatabase::remove_application_font
]
sourcepub fn set_font<F: FontTrait<'a>>(arg0: &F)
pub fn set_font<F: FontTrait<'a>>(arg0: &F)
Changes the default application font to font.
See also: [font()
]
sourcepub fn clipboard() -> Option<Clipboard<'a>>
pub fn clipboard() -> Option<Clipboard<'a>>
Returns the object for interacting with the clipboard.
sourcepub fn palette() -> Palette<'a>
pub fn palette() -> Palette<'a>
This signal is emitted when the palette of the application changes.
See also: [palette()
]
Returns the default application palette.
See also: [set_palette()
]
sourcepub fn set_palette<P: PaletteTrait<'a>>(pal: &P)
pub fn set_palette<P: PaletteTrait<'a>>(pal: &P)
Changes the default application palette to pal.
See also: [palette()
]
sourcepub fn keyboard_modifiers() -> KeyboardModifiers
pub fn keyboard_modifiers() -> 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 events).
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.
See also: [mouse_buttons()
]
[query_keyboard_modifiers()
]
sourcepub fn query_keyboard_modifiers() -> KeyboardModifiers
pub fn query_keyboard_modifiers() -> 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.
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.
See also: [keyboard_modifiers()
]
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 events).
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 is returned.
See also: [keyboard_modifiers()
]
pub fn set_layout_direction(direction: LayoutDirection)
sourcepub fn layout_direction() -> LayoutDirection
pub fn layout_direction() -> LayoutDirection
On system start-up, the default layout direction depends on the application’s language.
The notifier signal was introduced in Qt 5.4.
See also: Widget::layout_direction()
[is_left_to_right()
]
[is_right_to_left()
]
sourcepub fn is_right_to_left() -> bool
pub fn is_right_to_left() -> bool
Returns true
if the application’s layout direction is
Qt::RightToLeft; otherwise returns false.
See also: [layout_direction()
]
[is_left_to_right()
]
sourcepub fn is_left_to_right() -> bool
pub fn is_left_to_right() -> bool
Returns true
if the application’s layout direction is
Qt::LeftToRight; otherwise returns false.
See also: [layout_direction()
]
[is_right_to_left()
]
sourcepub fn set_desktop_settings_aware(on: bool)
pub fn set_desktop_settings_aware(on: bool)
Sets whether Qt should use the system’s standard colors, fonts, etc., to
on. By default, this is true.
This function must be called before creating the QGuiApplication object, like this:
See also: [desktop_settings_aware()
]
sourcepub fn desktop_settings_aware() -> bool
pub fn desktop_settings_aware() -> bool
Returns true
if Qt is set to use the system’s standard colors, fonts, etc.;
otherwise returns false.
The default is true.
See also: [set_desktop_settings_aware()
]
pub fn set_quit_on_last_window_closed(quit: bool)
sourcepub fn quit_on_last_window_closed() -> bool
pub fn quit_on_last_window_closed() -> bool
The default is true.
If this property is true,
the applications quits when the last visible
primary window (i.e. window with no parent) is closed.
See also: [quit()
]
Window::close
sourcepub fn application_state() -> ApplicationState
pub fn application_state() -> ApplicationState
Returns the current state of the application.
You can react to application state changes to perform actions such as stopping/resuming CPU-intensive tasks, freeing/loading resources or saving/restoring application data.
This signal is emitted when the state of the application changes.
See also: [application_state()
]
sourcepub fn exec() -> i32
pub fn exec() -> i32
Enters the main event loop and waits until exit() is called, and then returns the value that was set to exit() (which is 0 if exit() is called via 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().
To make your application perform idle processing, e.g., 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().
We recommend that you connect clean-up code to the
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.
See also: quitOnLastWindowClosed
[quit()
]
[exit()
]
[process_events()
]
CoreApplication::exec
sourcepub fn is_session_restored(&self) -> bool
pub fn is_session_restored(&self) -> bool
Returns true
if the application has been restored from an earlier
session
; otherwise returns false.
See also: [session_id()
]
[commit_data_request()
]
[save_state_request()
]
sourcepub fn session_id(&self) -> String
pub fn session_id(&self) -> String
Returns the current session’s identifier.
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.
See also: [is_session_restored()
]
[session_key()
]
[commit_data_request()
]
[save_state_request()
]
sourcepub fn session_key(&self) -> String
pub fn session_key(&self) -> String
Returns the session key in the current 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 every time the session is saved. If the shutdown process is cancelled, another session key will be used when shutting down again.
See also: [is_session_restored()
]
[session_id()
]
[commit_data_request()
]
[save_state_request()
]
sourcepub fn is_saving_session(&self) -> bool
pub fn is_saving_session(&self) -> bool
Returns true
if the application is currently saving the
session
; otherwise returns false.
This is true
when commitDataRequest() and saveStateRequest() are emitted,
but also when the windows are closed afterwards by session management.
See also: [session_id()
]
[commit_data_request()
]
[save_state_request()
]
sourcepub fn is_fallback_session_management_enabled() -> bool
pub fn is_fallback_session_management_enabled() -> bool
Returns whether QGuiApplication will use fallback session management.
The default is true.
If this is true
and the session manager allows user interaction,
QGuiApplication will try to close toplevel windows after
commitDataRequest() has been emitted. If a window cannot be closed, session
shutdown will be canceled and the application will keep running.
Fallback session management only benefits applications that have an feature or other logic that prevents closing a toplevel window depending on certain conditions, and that do nothing to explicitly implement session management. In applications that do implement session management using the proper session management API, fallback session management interferes and may break session management logic.
Warning: If all windows are closed due to fallback session management
and quitOnLastWindowClosed() is true,
the application will quit before
it is explicitly instructed to quit through the platform’s session
management protocol. That violation of protocol may prevent the platform
session manager from saving application state.
See also: [set_fallback_session_management_enabled()
]
[SessionManager::allows_interaction
]
[save_state_request()
]
[commit_data_request()
]
{Session Management}
sourcepub fn set_fallback_session_management_enabled(arg0: bool)
pub fn set_fallback_session_management_enabled(arg0: bool)
Sets whether QGuiApplication will use fallback session management to enabled.
See also: [is_fallback_session_management_enabled()
]
sourcepub fn sync()
pub fn sync()
Function that can be used to sync Qt state with the Window Systems state.
This function will first empty Qts events by calling QCoreApplication::processEvents(), then the platform plugin will sync up with the windowsystem, and finally Qts events will be delived by another call to QCoreApplication::processEvents();
This function is timeconsuming and its use is discouraged.
pub fn set_about_to_quit_event<F>(&self, func: F) -> &Selfwhere
F: Fn() + 'a,
pub fn set_custom_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&Event<'_>) + 'a,
pub fn build(&self) -> Self
Trait Implementations
sourceimpl<'a> Clone for GuiApplication<'a>
impl<'a> Clone for GuiApplication<'a>
sourcefn clone(&self) -> GuiApplication<'a>
fn clone(&self) -> GuiApplication<'a>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more