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



  • 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.



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

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

    }
    @



  • 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]



  • 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.
    }
    }
    }
    @



  • 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]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.