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. best practices when switching windows
Forum Updated to NodeBB v4.3 + New Features

best practices when switching windows

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qt-quick
4 Posts 2 Posters 2.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.
  • C Offline
    C Offline
    clarity
    wrote on 24 Feb 2016, 18:49 last edited by
    #1

    I'm developing an application that's not too big, but it has multiple screens.

    What are the ways of switching between screens, and what's the best practices?

    This is a vague question, and I'm not expecting code samples. I can google the docs for that.

    Thanks!
    Ryan

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 24 Feb 2016, 19:03 last edited by
      #2

      I'm not sure what you mean by "screens", but you can take a look at QTabWidget or QStackedWidget. If it's something like a wizard take a look at QWizard.

      C 1 Reply Last reply 24 Feb 2016, 19:21
      0
      • C Chris Kawa
        24 Feb 2016, 19:03

        I'm not sure what you mean by "screens", but you can take a look at QTabWidget or QStackedWidget. If it's something like a wizard take a look at QWizard.

        C Offline
        C Offline
        clarity
        wrote on 24 Feb 2016, 19:21 last edited by
        #3

        @Chris-Kawa What I mean by screens is different windows. For example, I'm working on a block explorer for an alt coin (similar to bitcoin). I want to have one screen where it lists the blocks (integers), and when you click on it, it opens up a new window where you can see the transactions. I don't know if it just looks like a new window, and I'm actually changing what's in the window, or if it's actually a new window created.

        I have some code written in javascript/qml that i'll share that's badly written:
        Component {
        id: gridComp
        Row {
        Text {
        text: blocknum + " "

                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            list.currentIndex = index
                            var component = Qt.createComponent("qrc:/detail.qml")
                            var window    = component.createObject(mainWindow)
                            window.show()
                            mainWindow.hide()
                        }
                    }
        
                }
                Text {
                    text: time + " "
                }
            }
        }
        

        The problem with this is that overtime I click the blocknum it creates a new window, so that's not ideal. I can click it 100 times, and it'll create 100 different windows.

        Thanks!
        Ryan

        1 Reply Last reply
        0
        • C Offline
          C Offline
          clarity
          wrote on 24 Feb 2016, 20:31 last edited by
          #4

          I implemented the window change using a Layout. However, I'm not sure if this is the best approach.

          Here's the code:

          blocks.qml:
          import QtQuick 2.0
          import QtQuick.Controls 1.4
          import QtQuick.Layouts 1.2
          import QtQuick.Dialogs 1.2

          Item {
          ColumnLayout {
          id: mainLayout
          anchors.fill: parent
          anchors.margins: margin

              Text {
                  //id: tophead
                  text: mc.blockheight
              }
          
              ListView {
                  id: list
                  model: mc
                  Layout.fillHeight: true
                  delegate: gridComp
          
                  highlight: Rectangle {
                       color: 'grey'
                  }
          
                  focus: true
          
                  Keys.onPressed: {
                      var pageDown = currentIndex+10;
                      var pageUp = currentIndex-10;
                      if (event.key === Qt.Key_PageDown && event.modifiers === Qt.NoModifier) {
                          currentIndex = pageDown >= count ? count-1 : pageDown;
                          event.accepted = true;
                      }
                      if (event.key === Qt.Key_PageUp && event.modifiers === Qt.NoModifier) {
                          currentIndex = pageUp < 0 ? 0 : pageUp;
                          event.accepted = true;
                      }
                  }
          
              }
          }
          
          Component {
              id: gridComp
              Row {
                  Text {
                      text: blocknum + " "
          
                      MouseArea {
                          anchors.fill: parent
                          onClicked: {
                              list.currentIndex = index;
          
                              /*
                              var component = Qt.createComponent("qrc:/detail.qml")
                              var window    = component.createObject(mainWindow)
                              window.show()
                              mainWindow.hide()
                              */
          
                              ld.setSource("detail.qml")
                          }
                      }
                  }
                  Text {
                      text: time + " "
                  }
              }
          }
          

          }

          detail.qml:
          import QtQuick 2.5
          import QtQuick.Controls 1.4
          import QtQuick.Layouts 1.2
          import QtQuick.Dialogs 1.2

          Item {
          id: detailWindow
          visible: true

          ColumnLayout {
              Text {
                  text: "detail.qml"
              }
          
              Button {
                  text: "Back"
          
                  onClicked: {
                      ld.source = "blocks.qml"
                  }
              }
          }
          

          }

          main.qml:
          import QtQuick 2.5
          import QtQuick.Controls 1.4
          import QtQuick.Layouts 1.2
          import QtQuick.Dialogs 1.2

          ApplicationWindow {
          id: mainWindow
          visible: true
          width: 640
          height: 480
          title: qsTr("Block Explorer")

          Loader {
              id: ld
              anchors.fill: parent
              source: "blocks.qml"
          }
          

          }

          Thanks,
          Ryan

          1 Reply Last reply
          0

          3/4

          24 Feb 2016, 19:21

          • Login

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