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. What to do if I want to reuse element as well as call different dialog each time?

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

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 2.1k Views
  • 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 Offline
    O Offline
    owenzhao
    wrote on last edited by
    #1

    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
    0
    • G Offline
      G Offline
      GentooXativa
      wrote on last edited by
      #2

      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
      0
      • O Offline
        O Offline
        owenzhao
        wrote on last edited by
        #3

        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
        0
        • G Offline
          G Offline
          GentooXativa
          wrote on last edited by
          #4

          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
          0
          • O Offline
            O Offline
            owenzhao
            wrote on last edited by
            #5

            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
            0

            • Login

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