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. open new window on button click
Forum Updated to NodeBB v4.3 + New Features

open new window on button click

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 3 Posters 4.2k Views 2 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.
  • L Offline
    L Offline
    leon missoul
    wrote on 12 Jan 2021, 16:00 last edited by
    #1

    It's a really simple, maybe stupid question, but I've been looking for this all day without success.

    I have a main window (main.qml) with a button. When this button is clicked I want to open a new window (window2.qml). I want to do this using the 'onClicked:' component, and found online, to open a window, I can use 'show()', but I have not been successful in combining these two.

    I'm new to this, would love every answer :)

    Thanks in advance.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 14 Jan 2021, 05:52 last edited by
      #2

      Something like this should work:

      Button {
        text: "Open window"
        onClicked: window2.show()
      }
      
      // You need to rename window2.qml to Window2.qml
      Window2 {
        id: window2
        visible: false
      }
      

      Or you can use Loader to defer loading of the second window's QML code.

      (Z(:^

      1 Reply Last reply
      1
      • S Offline
        S Offline
        sluci
        wrote on 16 Jan 2021, 17:31 last edited by
        #3
        //*** help button
                Button{
                    id: helpButton
                    height: hButton
                    text: qsTr("Help")
                    onClicked:{
                        var component = Qt.createComponent("HelpForm.qml")
                        var window    = component.createObject()
                        window.show()
                    }
                }
        
        

        I hope this can help you ....

        1 Reply Last reply
        0

        1/3

        12 Jan 2021, 16:00

        • Login

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