Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    What to do if I want to reuse element as well as call different dialog each time?

    QML and Qt Quick
    2
    5
    1877
    Loading More Posts
    • 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.
    • O
      owenzhao last edited by

      In my setting page, I just want to reuse some code, which is a Text Element, follow by a Button Element, I will open a dialog when button is clicked. The problem is I want to open a diffenent dialog each time. So I don't know what to do now. It seems that I have to drop reusing my code, or the I can't get the dialog open.
      My code is like this, SettingPageElement.qml:
      @// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
      import QtQuick 1.1
      import com.nokia.symbian 1.1

      Flow {
      property string displayText
      property string buttonText
      Text {
      color: platformStyle.colorNormalLight
      anchors.left: parent.left
      width: 360
      font.pixelSize: platformStyle.fontSizeLarge
      text: displayText
      }
      Button {
      anchors.right: parent.right
      width: 270
      font.pixelSize: platformStyle.fontSizeMedium
      text: buttonText
      onClicked: //I want to open a different dialog each time.
      }
      }
      @

      my SettingPage.qml will like this:
      @Column {
      SettingPageElement {
      id: firstSetting
      displayText: "Time property"
      buttonText: "30"
      }
      }@
      Anyone has an idea of what should I do?
      Thank you.

      1 Reply Last reply Reply Quote 0
      • G
        GentooXativa last edited by

        Try to encapsulate inside a Item object
        @
        Item {
        id: mItem

         Flow {
              ............
         }
        

        }
        @

        Jose Vicente Giner Sanchez - Senior Mobile Developer

        www.gigigo.com

        C/ Dr. Zamenhof 36bis, 1ºA 28027 Madrid
        T: +34 917431436

        1 Reply Last reply Reply Quote 0
        • O
          owenzhao last edited by

          Thank you. I know by using this can solve the problem. But I want to reuse the codes, which means I don't need to type them each time.

          [quote author="GentooXativa" date="1334736490"]Try to encapsulate inside a Item object
          @
          Item {
          id: mItem

           Flow {
                ............
           }
          

          }
          @[/quote]

          1 Reply Last reply Reply Quote 0
          • G
            GentooXativa last edited by

            You dont have to rewrite the same all the time, try this:

            @
            // import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
            import QtQuick 1.1
            import com.nokia.symbian 1.1

            Item{

            Flow {
            property string displayText
            property string buttonText
            Text {
            color: platformStyle.colorNormalLight
            anchors.left: parent.left
            width: 360
            font.pixelSize: platformStyle.fontSizeLarge
            text: displayText
            }
            Button {
            anchors.right: parent.right
            width: 270
            font.pixelSize: platformStyle.fontSizeMedium
            text: buttonText
            onClicked: //I want to open a different dialog each time.
            }
            }
            }
            @

            Jose Vicente Giner Sanchez - Senior Mobile Developer

            www.gigigo.com

            C/ Dr. Zamenhof 36bis, 1ºA 28027 Madrid
            T: +34 917431436

            1 Reply Last reply Reply Quote 0
            • O
              owenzhao last edited by

              Then? I want to @ onClicked: //I want to open a different dialog each time.@
              for the firstSetting, it will be @ onClicked: firstDialog.open()@
              for the secondSetting, it will be @ onClicked: secondDialog.open()@

              I think maybe I can replace it to @ onClicked:openDialog(dialogUrl)@
              and reimplement the function like
              @ function openDialog(dialogUrl) {
              var component = Qt.createComponent(dialogUrl);
              if (component.status == Component.Ready) {
              var dialog = component.createObject(settingPage);
              }
              }@
              [quote author="GentooXativa" date="1334736812"]You dont have to rewrite the same all the time, try this:

              @
              // import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
              import QtQuick 1.1
              import com.nokia.symbian 1.1

              Item{

              Flow {
              property string displayText
              property string buttonText
              Text {
              color: platformStyle.colorNormalLight
              anchors.left: parent.left
              width: 360
              font.pixelSize: platformStyle.fontSizeLarge
              text: displayText
              }
              Button {
              anchors.right: parent.right
              width: 270
              font.pixelSize: platformStyle.fontSizeMedium
              text: buttonText
              onClicked: //I want to open a different dialog each time.
              }
              }
              }
              @[/quote]

              1 Reply Last reply Reply Quote 0
              • First post
                Last post