This page has been translated automatically.
UnigineScript
The Language
Core Library
Engine Library
Node-Related Classes
GUI-Related Classes
Plugins Library
Samples
C++ API
API Reference
Integration Samples
Usage Examples
C++ Plugins
Content Creation
Materials
Unigine Material Library
Tutorials
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

User Interfaces for Unigine::Widgets

You can use user interface files (*.ui) to describe how widgets are laid out. Two types of UI files are supported:

  • UI files created in Unigine UI syntax, manually. Such files are handled using Unigine::Widgets::UserInterface class.
  • UI files exported from the Qt Designer. Such files are handled using Unigine::Widgets::NativeInterface class.

How to Load Unigine UI

To load a Unigine-native user interface file, take the following steps:

  1. Include the UserInterface header. All other Unigine::Widgets headers are already included in it.
    Source code (UnigineScript)
    #include <core/systems/widgets/widget_interface.h>
    
  2. Declare UserInterface and the root widgets from the UI file in the global scope.
    Source code (UnigineScript)
    #include <core/systems/widgets/widget_interface.h>
    
    Unigine::Widgets::UserInterface ui;
    Unigine::Widgets::Window window;
    
  3. Load the user interface file. You also need to add root widgets to the rendered GUI for them to become visible.
    Source code (UnigineScript)
    int init() {
    	
    	// You can declare the namespace for convenience
    	using Unigine::Widgets;
    	
    	// Load UI file in Unigine syntax
    	ui = new UserInterface("samples/systems/widgets/widgets_01.ui");
    	
    	// Render the root widget
    	addChild(window,ALIGN_OVERLAP | ALIGN_CENTER);
    	
    	return 1;
    }
    
    int shutdown() {
    	
    	// Delete UserInterface with all widgets loaded from it
    	delete ui;
    	
    	return 1;
    }
    

How to Load Qt UI

UI files exported from Qt Designer are handled in the similar manner as Unigine UI with the exception that Unigine::Widgets::NativeInterface is used.

  1. Include the interface header. All other Unigine::Widgets headers are already included in it.
    Source code (UnigineScript)
    #include <core/systems/widgets/widget_interface.h>
    
  2. Declare NativeInterface and the root widgets from the UI file in the global scope.
    Source code (UnigineScript)
    #include <core/systems/widgets/widget_interface.h>
    
    Unigine::Widgets::NativeInterface qt_ui;
    Unigine::Widgets::Window window;
    
  3. Load the user interface file. You also need to add root widgets to the rendered GUI for them to become visible.
    Source code (UnigineScript)
    int init() {
    	
    	// You can declare the namespace for convenience
    	using Unigine::Widgets;
    	
    	// Load UI file created in Qt Designer
    	qt_ui = new NativeInterface("samples/systems/widgets/widgets_02.ui");
    	
    	// Render the root widget
    	addChild(window,ALIGN_OVERLAP | ALIGN_CENTER);
    	
    	return 1;
    }
    
    int shutdown() {
    	
    	// Delete NativeInterface with all widgets loaded from it
    	delete qt_ui;
    	
    	return 1;
    }
    
Last update: 2017-07-03
Build: ()