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
Qt 6.11 is out! See what's new in the release blog

open new window on button click

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 3 Posters 5.4k 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 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
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on 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 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

        • Login

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