InteractiveWindow

Description

An InteractiveWindow can display either inside Interface or in its own window separate from the Interface window. The window content is defined by a QML file, which can optionally include a WebView control that embeds an HTML web page. (The WebView control is defined by a "WebView.qml" file included in the Interface install.)

Create using Desktop.createWindow.

Supported Script Types: Interface Scripts • Client Entity Scripts • Avatar Scripts

Constructor
new InteractiveWindow( )

Properties

Name Type Summary
title string The title of the window.
position Vec2 The position of the window, in pixels.
size Vec2 The size of the window, in pixels.
visible boolean true if the window is visible, false if it isn't.
presentationMode InteractiveWindow.PresentationMode The presentation mode of the window: Desktop.PresentationMode.VIRTUAL to display the window inside Interface, .NATIVE to display it as its own separate window.

Methods

Name Return Value Summary
close None Closes the window. It can then no longer be used.
emitScriptEvent None Sends a message to an embedded HTML web page. To receive the message, the HTML page's script must connect to the EventBridge that is automatically provided to the script:
EventBridge.scriptEventReceived.connect(function(message) {
    ...
});
emitWebEvent None

Deprecated: This function is deprecated and will be removed from the API.

raise None Raises the window to the top.
sendToQml None Sends a message to the QML page. To receive the message, the QML page must implement a function:
function fromScript(message) {
  ...
}
show None Makes the window visible and raises it to the top.

Signals

Name Summary
closed Triggered when the window is closed.
fromQml Triggered when a message from the QML page is received. The QML page can send a message (string or object) by calling:
sendToScript(message);
positionChanged Triggered when the window's position changes.
presentationModeChanged Triggered when the window's presentation mode changes.
qmlToScript

Deprecated: This signal is deprecated and will be removed from the API.

scriptEventReceived

Deprecated: This signal is deprecated and will be removed from the API.

sizeChanged Triggered when the window's size changes.
titleChanged Triggered when window's title changes.
visibleChanged Triggered when the window is made visible or invisible, or is closed.
webEventReceived Triggered when a message from an embedded HTML web page is received. The HTML web page can send a message by calling:
EventBridge.emitWebEvent(message);

Type Definitions

DockArea
Type: number

A docking location of an InteractiveWindow.

ValueName

Description
0TOPDock to the top edge of the Interface window.
1BOTTOMDock to the bottom edge of the Interface window.
2LEFTDock to the left edge of the Interface window.
3RIGHTDock to the right edge of the Interface window.

DockAreas
Type: object

The possible docking locations of an InteractiveWindow.

Properties

Name Type Summary
TOP InteractiveWindow.DockArea Dock to the top edge of the Interface window.
BOTTOM InteractiveWindow.DockArea Dock to the bottom edge of the Interface window.
LEFT InteractiveWindow.DockArea Dock to the left edge of the Interface window.
RIGHT InteractiveWindow.DockArea Dock to the right edge of the Interface window.
Flags
Type: number

A set of flags controlling InteractiveWindow behavior. The value is constructed by using the | (bitwise OR) operator on the individual flag values.

Flag NameValueDescription
ALWAYS_ON_TOP1The window always displays on top.
CLOSE_BUTTON_HIDES2The window hides instead of closing when the user clicks the "close" button.

PresentationMode
Type: number

A display mode for an InteractiveWindow.

ValueName

Description
0VIRTUALThe window is displayed inside Interface: in the desktop window in desktop mode or on the HUD surface in HMD mode.
1NATIVEThe window is displayed separately from the Interface window, as its own separate window.

PresentationModes
Type: object

The possible display modes for an InteractiveWindow.

Properties

Name Type Summary
VIRTUAL InteractiveWindow.PresentationMode The window is displayed inside Interface: in the desktop window in desktop mode or on the HUD surface in HMD mode.
NATIVE InteractiveWindow.PresentationMode The window is displayed separately from the Interface window, as its own separate window.
PresentationWindowInfo
Type: object

Configures how a NATIVE window is displayed.

Properties

Name Type Summary
dockArea InteractiveWindow.DockArea The edge of the Interface window to dock to.
Properties
Type: object

A set of properties used when creating an InteractiveWindow.

Properties

Name Type Attributes Summary
title string <optional>
The title of the window.

Default Value: "InteractiveWindow

position Vec2 <optional>
The initial position of the window, in pixels.
size Vec2 <optional>
The initial size of the window, in pixels
visible boolean <optional>
true to make the window visible when created, false to make it invisible.

Default Value: true

presentationMode InteractiveWindow.PresentationMode <optional>
Desktop.PresentationMode.VIRTUAL to display the window inside Interface, .NATIVE to display it as its own separate window.

Default Value: Desktop.PresentationMode.VIRTUAL

presentationWindowInfo InteractiveWindow.PresentationWindowInfo <optional>
Controls how a NATIVE window is displayed. If used, the window is docked to the specified edge of the Interface window, otherwise the window is displayed as its own separate window.
additionalFlags InteractiveWindow.AdditionalFlags <optional>
Window behavior flags in addition to "native window flags" (minimize/maximize/close), set at window creation. Possible flag values are provided as Desktop.ALWAYS_ON_TOP and Desktop.CLOSE_BUTTON_HIDES. Additional flag values can be found on Qt's website at https://doc.qt.io/qt-5/qt.html#WindowType-enum.

Default Value: 0

overrideFlags InteractiveWindow.OverrideFlags <optional>
Window behavior flags instead of the default window flags. Set at window creation. Possible flag values are provided as Desktop.ALWAYS_ON_TOP and Desktop.CLOSE_BUTTON_HIDES. Additional flag values can be found on Qt's website at https://doc.qt.io/qt-5/qt.html#WindowType-enum.

Default Value: 0

Method Details

(static) close( )

Closes the window. It can then no longer be used.

(static) emitScriptEvent( message )

Sends a message to an embedded HTML web page. To receive the message, the HTML page's script must connect to the EventBridge that is automatically provided to the script:

EventBridge.scriptEventReceived.connect(function(message) {
    ...
});

Parameters

Name Type Description
message string | object The message to send to the embedded HTML web page.
(static) emitWebEvent( message )

Deprecated: This function is deprecated and will be removed from the API.

Parameters

Name Type Description
message object | string The message.
(static) raise( )

Raises the window to the top.

(static) sendToQml( message )

Sends a message to the QML page. To receive the message, the QML page must implement a function:

function fromScript(message) {
  ...
}

Parameters

Name Type Description
message string | object The message to send to the QML page.
Examples

Send and receive messages with a QML window.

// JavaScript file.

var qmlWindow = Desktop.createWindow(Script.resolvePath("QMLWindow.qml"), {
    title: "QML Window",
    size: { x: 400, y: 300 }
});

qmlWindow.fromQml.connect(function (message) {
    print("Message received: " + message);
});

Script.setTimeout(function () {
    qmlWindow.sendToQml("Hello world!");
}, 2000);

Script.scriptEnding.connect(function () {
    qmlWindow.close();
});
// QML file, "QMLWindow.qml".

import QtQuick 2.5
import QtQuick.Controls 1.4

Rectangle {

    function fromScript(message) {
        text.text = message;
        sendToScript("Hello back!");
    }

    Label {
        id: text
        anchors.centerIn: parent
        text: "..."
    }
}
(static) show( )

Makes the window visible and raises it to the top.

Signal Details

closed( )
Returns: Signal

Triggered when the window is closed.

fromQml( message )
Returns: Signal

Triggered when a message from the QML page is received. The QML page can send a message (string or object) by calling:

sendToScript(message);

Parameters

Name Type Description
message string | object The message received.
positionChanged( )
Returns: Signal

Triggered when the window's position changes.

presentationModeChanged( )
Returns: Signal

Triggered when the window's presentation mode changes.

qmlToScript( message )
Returns: Signal

Deprecated: This signal is deprecated and will be removed from the API.

Parameters

Name Type Description
message object
scriptEventReceived( message )
Returns: Signal

Deprecated: This signal is deprecated and will be removed from the API.

Parameters

Name Type Description
message object The message.
sizeChanged( )
Returns: Signal

Triggered when the window's size changes.

titleChanged( )
Returns: Signal

Triggered when window's title changes.

visibleChanged( )
Returns: Signal

Triggered when the window is made visible or invisible, or is closed.

webEventReceived( message )
Returns: Signal

Triggered when a message from an embedded HTML web page is received. The HTML web page can send a message by calling:

EventBridge.emitWebEvent(message);

Parameters

Name Type Description
message string | object The message received.