OverlayWindow

Description

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

A OverlayWindow displays a QML window inside Interface.

The QML can optionally include a WebView control that embeds an HTML-based windows. (The WebView control is defined by a "WebView.qml" file included in the Interface install.) Alternatively, an OverlayWebWindow can be used for HTML-based windows.

Create using new OverlayWindow(...).

Properties

Name Type Summary
position Vec2

The position of the window, in pixels.

size Vec2

The size of the window interior, in pixels.

visible boolean

true if the window is visible, false if it isn't.

Constructor
new OverlayWindow( titleOrPropertiesopt, sourceopt, widthopt, heightopt )

Parameters

Name Type Attributes Default Value Description
titleOrProperties string | OverlayWindow.Properties <optional>
"WebWindow"

The window's title or initial property values.

source string <optional>

The source of the QML to display. Not used unless the first parameter is the window title.

width number <optional>
0

The width of the window interior, in pixels. Not used unless the first parameter is the window title.

height number <optional>
0

The height of the window interior, in pixels. Not used unless the first parameter is the window title.

Methods

Name Return Value Summary
clearDebugWindow None

Calls a clearWindow() function if present in the QML.

close None

Closes the window.

Note: The window also closes when the script ends.

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 for the script:

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

Deprecated: This function is deprecated and will be removed.

getEventBridge object

Deprecated: This method is deprecated and will be removed.

getPosition Vec2

Gets the position of the window.

getSize Vec2

Gets the size of the window interior.

hasClosed None

Deprecated: This method is deprecated and will be removed.

hasMoved None

Deprecated: This method is deprecated and will be removed.

initQml None

Deprecated: This method is deprecated and will be removed.

isVisible boolean

Gets whether the window is shown or hidden.

qmlToScript None

Deprecated: This method is deprecated and will be removed.

raise None

Raises the window to the top.

sendToQml None

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

function fromScript(message) {
  ...
}
setPosition None

Sets the position of the window, from a Vec2.

setPosition None

Sets the position of the window, from a pair of numbers.

setSize None

Sets the size of the window interior, from a Vec2.

setSize None

Sets the size of the window interior, from a pair of numbers.

setTitle None

Sets the window title.

setVisible None

Shows or hides the window.

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);
moved

Triggered when the window changes position.

positionChanged

Triggered when the window changes position.

resized

Triggered when the window changes size.

scriptEventReceived

Deprecated: This signal is deprecated and will be removed.

sizeChanged

Triggered when the window changes size.

visibleChanged

Triggered when the window is hidden or shown.

webEventReceived

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

EventBridge.emitWebEvent(message);

Type Definitions

Properties
Type: object

Properties used to initialize an OverlayWindow or OverlayWebWindow.

Properties

Name Type Attributes Summary
title string <optional>

The window title.

Default Value: "WebWindow

source string <optional>

The source of the QML or HTML to display.

width number <optional>

The width of the window interior, in pixels.

Default Value: 0

height number <optional>

The height of the window interior, in pixels.

Default Value: 0

visible boolean <optional>

true if the window should be visible, false if it shouldn't.

Default Value: true

Method Details

(static) clearDebugWindow( )

Calls a clearWindow() function if present in the QML.

(static) close( )

Closes the window.

Note: The window also closes when the script ends.

(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 for the script:

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

Parameters

Name Type Description
message string | object

The message to send to the embedded HTML page.

(static) emitWebEvent( message )

Deprecated: This function is deprecated and will be removed.

Parameters

Name Type Description
message object | string

The message.

(static) getEventBridge( ) → {object}
Returns: Object.

Deprecated: This method is deprecated and will be removed.

(static) getPosition( ) → {Vec2}
Returns: The position of the window, in pixels.

Gets the position of the window.

(static) getSize( ) → {Vec2}
Returns: The size of the window interior, in pixels.

Gets the size of the window interior.

(static) hasClosed( )

Deprecated: This method is deprecated and will be removed.

(static) hasMoved( position )

Deprecated: This method is deprecated and will be removed.

Parameters

Name Type Description
position Vec2

Position.

(static) initQml( properties )

Deprecated: This method is deprecated and will be removed.

Parameters

Name Type Description
properties OverlayWindow.Properties

Properties.

(static) isVisible( ) → {boolean}
Returns: code>true if the window is shown, false if it is hidden.

Gets whether the window is shown or hidden.

(static) qmlToScript( message )

Deprecated: This method is deprecated and will be removed.

Parameters

Name Type Description
message object

Message.

(static) raise( )

Raises the window to the top.

(static) sendToQml( message )

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

function fromScript(message) {
  ...
}

Parameters

Name Type Description
message string | object

The message to send to the QML.

Examples

Send and receive messages with a QML window.

// JavaScript file.

var overlayWindow = new OverlayWindow({
    title: "Overlay Window",
    source: Script.resolvePath("OverlayWindow.qml"),
    width: 400,
    height: 300
});

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

Script.setTimeout(function () {
    overlayWindow.sendToQml("Hello world!");
}, 2000);
// QML file, "OverlayWindow.qml".

import QtQuick 2.5
import QtQuick.Controls 1.4

Rectangle {
    width: parent.width
    height: parent.height

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

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

Sets the position of the window, from a Vec2.

Parameters

Name Type Description
position Vec2

The position of the window, in pixels.

(static) setPosition( x, y )

Sets the position of the window, from a pair of numbers.

Parameters

Name Type Description
x number

The x position of the window, in pixels.

y number

The y position of the window, in pixels.

(static) setSize( size )

Sets the size of the window interior, from a Vec2.

Parameters

Name Type Description
size Vec2

The size of the window interior, in pixels.

(static) setSize( width, height )

Sets the size of the window interior, from a pair of numbers.

Parameters

Name Type Description
width number

The width of the window interior, in pixels.

height number

The height of the window interior, in pixels.

(static) setTitle( title )

Sets the window title.

Parameters

Name Type Description
title string

The window title.

(static) setVisible( visible )

Shows or hides the window.

Parameters

Name Type Description
visible boolean

code>true to show the window, false to hide it.

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 object

The message received.

moved( position )
Returns: Signal

Triggered when the window changes position.

Parameters

Name Type Description
position Vec2

The position of the window, in pixels.

positionChanged( )
Returns: Signal

Triggered when the window changes position.

resized( size )
Returns: Signal

Triggered when the window changes size.

Parameters

Name Type Description
size Size

The size of the window interior, in pixels.

scriptEventReceived( message )
Returns: Signal

Deprecated: This signal is deprecated and will be removed.

Parameters

Name Type Description
message object

The message.

sizeChanged( )
Returns: Signal

Triggered when the window changes size.

visibleChanged( )
Returns: Signal

Triggered when the window is hidden or shown.

webEventReceived( message )
Returns: Signal

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

EventBridge.emitWebEvent(message);

Parameters

Name Type Description
message string | object

The message received.