Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to load any Qml file into a rectangle in main.qml?
Forum Updated to NodeBB v4.3 + New Features

How to load any Qml file into a rectangle in main.qml?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • AlperA Offline
    AlperA Offline
    Alper
    wrote on last edited by Alper
    #1

    Hi

    i have two qml files, main.qml and gui1.qml.
    gui1.qml is a Gui for emulating a hardware device and it works lonely.
    i need to show that Gui in my main window. (inside a rectangle or in layout).
    i wrote these codes below but the gui1.qml appears in a new window. i need it appear ** inside of main window**.
    pls help me.

    // This is main.qml file
    import QtQuick 2.3
    import QtQuick.Window 2.2
    import QtQuick.Controls 1.4
    Window
    {
        width: 800
        height: 500
        visible: true
        id:mainWin
    
    Rectangle
    {
        x: 10
        y: 10
        width: 100
        height: 100
        id: contRect
    }
    
        Item {
            id: container
            width: 500; height: 100
            x:100
            y:100
    
            function createRadioWindow(){
                var component = Qt.createComponent("file:gui1.qml");
    
                var object  = component.createObject(container, {"x": 0, "y": 0});
            }
        }
    }
    

    and

    //This is gui1.qml file
    import QtQuick 2.3
    import QtQuick.Window 2.2
    import QtQuick.Controls 1.4
    import QtQuick.Controls.Styles 1.2
    import QtQuick.Extras 1.4
    window
    {
    	/*
    	
    	Some images,controls,rectangles,events ...
    	
    	*/
    }  
    
    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi, just change gui1.qml to something like:

      Item {
      // ...
      }
      
      AlperA 1 Reply Last reply
      1
      • ? A Former User

        Hi, just change gui1.qml to something like:

        Item {
        // ...
        }
        
        AlperA Offline
        AlperA Offline
        Alper
        wrote on last edited by
        #3

        @Wieland
        it works!
        Thank you

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved