maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   QML and SelectionDialog [and other QML-related questions] (https://talk.maemo.org/showthread.php?t=85113)

marmistrz 2012-06-26 14:47

QML and SelectionDialog [and other QML-related questions]
 
1 Attachment(s)
Hi
I'm learning QML.
My code is:
Code:

import QtQuick 1.0
import org.maemo.fremantle 1.0

Column
{
    property color fontcolor: "white"
    Row
    {
        width: parent.width
        CheckBox
        {
            id: tracksrc
            //text: "Select track from library"
            checked: true
            //checkable: true
        }
        Label
        {
            id: tracksrcText
            text: "Select track from library"
            anchors.verticalCenter: tracksrc.verticalCenter
            color: fontcolor
        }
    }

    Label
    {
        id: selecttracklabel
        text: "Selected track"
        color: fontcolor
    }
    Button
    {
        id: selecttrack
        text: "No track selected"
        checkable: false
        width: parent.width
    }

    SelectionDialog
    {
        id: lyricssrcdialog
        titleText: "Download source"
        selectedIndex: 1
        model: ListModel
        {
            ListElement { name: "AZLyrics" }
        }
    }
    Button
    {
        id: lyricssrcbutton
        text: lyricssrcdialog.model.get(lyricssrcdialog.selectedIndex).name
        width: parent.width
        onClicked: { lyricssrcdialog.open(); }
    }

    Button
    {
        id: go
        text: "Go!"
        width: parent.width
    }
}

I'm attaching the log.
I want the lyricssrcbutton to display the currently selected option.
Why isn't it working. What's the problem with the loops?
Thanks in advance.

Slocan 2012-06-26 16:11

Re: QML and SelectionDialog
 
The SelectionDialog is in its own Popup window, you can't place it inside a Column/Row, so it's giving you those loop warnings (column and dialog battling out to see who will provide the layout).

dicksonleong8 2012-06-26 16:18

Re: QML and SelectionDialog
 
@Slocan are right

1 more thing is your SelectionDialog's selectedIndex should be start with 0, not 1

marmistrz 2012-06-27 15:28

Re: QML and SelectionDialog
 
I'm still having problems. The index set for 0 solves one the problem of a blank label, but
With this code:
Code:

import QtQuick 1.0
import org.maemo.fremantle 1.0
Rectangle
{
    property color fontcolor: "white"
    Column
    {
        id: c1
        Row
        {
            width: parent.width
            CheckBox
            {
                id: tracksrc
                //text: "Select track from library"
                checked: true
                //checkable: true
            }
            Label
            {
                id: tracksrcText
                text: "Select track from library"
                anchors.verticalCenter: tracksrc.verticalCenter
                color: fontcolor
            }
        }

        Label
        {
            id: selecttracklabel
            text: "Selected track"
            color: fontcolor
        }
        Button
        {
            id: selecttrack
            text: "No track selected"
            checkable: false
            width: parent.width
        }
    }
    Rectangle
    {
        id: r1
        anchors.top: c1.bottom
        SelectionDialog
        {
            id: lyricssrcdialog
            titleText: "Download source"
            selectedIndex: 0
            model: ListModel
            {
                ListElement { name: "AZLyrics" }
            }
        }
        Button
        {
            id: lyricssrcbutton
            text: lyricssrcdialog.model.get(lyricssrcdialog.selectedIndex).name
            width: parent.width
            onClicked: { lyricssrcdialog.open(); }
        }
    }
    Column
    {
        id: c2
        anchors.top: r1.bottom
        Button
        {
            id: go
            text: "Go!"
            width: parent.width
        }
    }
}

There's only black, blank screen showing up. If only the selectedIndex property is changed:
Code:

import QtQuick 1.0
import org.maemo.fremantle 1.0

Column
{
    property color fontcolor: "white"
    Row
    {
        width: parent.width
        CheckBox
        {
            id: tracksrc
            //text: "Select track from library"
            checked: true
            //checkable: true
        }
        Label
        {
            id: tracksrcText
            text: "Select track from library"
            anchors.verticalCenter: tracksrc.verticalCenter
            color: fontcolor
        }
    }

    Label
    {
        id: selecttracklabel
        text: "Selected track"
        color: fontcolor
    }
    Button
    {
        id: selecttrack
        text: "No track selected"
        checkable: false
        width: parent.width
    }

    SelectionDialog
    {
        id: lyricssrcdialog
        titleText: "Download source"
        selectedIndex: 0
        model: ListModel
        {
            ListElement { name: "AZLyrics" }
        }
    }
    Button
    {
        id: lyricssrcbutton
        text: lyricssrcdialog.model.get(lyricssrcdialog.selectedIndex).name
        width: parent.width
        onClicked: { lyricssrcdialog.open(); }
    }

    Button
    {
        id: go
        text: "Go!"
        width: parent.width
    }
}

then it's showing up alright, but throwing that load of loops detected as before. Where should I move the selection dialog?

ajalkane 2012-06-27 15:41

Re: QML and SelectionDialog
 
Quote:

Originally Posted by marmistrz (Post 1228242)
then it's showing up alright, but throwing that load of loops detected as before. Where should I move the selection dialog?

Perhaps like this (notice I wrapped Column inside Item):
Code:

Item {

Column
{
    property color fontcolor: "white"
    Row
    {
        width: parent.width
        CheckBox
        {
            id: tracksrc
            //text: "Select track from library"
            checked: true
            //checkable: true
        }
        Label
        {
            id: tracksrcText
            text: "Select track from library"
            anchors.verticalCenter: tracksrc.verticalCenter
            color: fontcolor
        }
    }

    Label
    {
        id: selecttracklabel
        text: "Selected track"
        color: fontcolor
    }
    Button
    {
        id: selecttrack
        text: "No track selected"
        checkable: false
        width: parent.width
    }

    Button
    {
        id: lyricssrcbutton
        text: lyricssrcdialog.model.get(lyricssrcdialog.selectedIndex).name
        width: parent.width
        onClicked: { lyricssrcdialog.open(); }
    }

    Button
    {
        id: go
        text: "Go!"
        width: parent.width
    }
}


    SelectionDialog
    {
        id: lyricssrcdialog
        titleText: "Download source"
        selectedIndex: 0
        model: ListModel
        {
            ListElement { name: "AZLyrics" }
        }
    }
}


marmistrz 2012-06-29 15:33

Re: QML and SelectionDialog
 
Quote:

Originally Posted by ajalkane (Post 1228245)
Perhaps like this (notice I wrapped Column inside Item):
Code:

Item {

Column
{
    property color fontcolor: "white"
    Row
    {
        width: parent.width
        CheckBox
        {
            id: tracksrc
            //text: "Select track from library"
            checked: true
            //checkable: true
        }
        Label
        {
            id: tracksrcText
            text: "Select track from library"
            anchors.verticalCenter: tracksrc.verticalCenter
            color: fontcolor
        }
    }

    Label
    {
        id: selecttracklabel
        text: "Selected track"
        color: fontcolor
    }
    Button
    {
        id: selecttrack
        text: "No track selected"
        checkable: false
        width: parent.width
    }

    Button
    {
        id: lyricssrcbutton
        text: lyricssrcdialog.model.get(lyricssrcdialog.selectedIndex).name
        width: parent.width
        onClicked: { lyricssrcdialog.open(); }
    }

    Button
    {
        id: go
        text: "Go!"
        width: parent.width
    }
}


    SelectionDialog
    {
        id: lyricssrcdialog
        titleText: "Download source"
        selectedIndex: 0
        model: ListModel
        {
            ListElement { name: "AZLyrics" }
        }
    }
}


With this code:
Code:

import QtQuick 1.0
import org.maemo.fremantle 1.0
Item
{
    Loader
    {
        id: goloader
        onLoaded: console.log("Go! clicked")
    }
    Loader
    {
        id: selecttrackloader
        onLoaded: console.log("Select track view loaded")
    }

    Column
    {
        property color fontcolor: "white"
        Row
        {
            width: parent.width
            CheckBox
            {
                id: tracksrc
                //text: "Select track from library"
                checked: true
                //checkable: true
            }
            Label
            {
                id: tracksrcText
                text: "Select track from library"
                anchors.verticalCenter: tracksrc.verticalCenter
                color: fontcolor
            }
        }

        Label
        {
            id: selecttracklabel
            text: "Selected track"
            color: fontcolor
        }
        Button
        {
            id: selecttrack
            text: "No track selected"
            checkable: false
            width: parent.width
            onClicked:
            {
            }
        }

        Button
        {
            id: lyricssrcbutton
            text: lyricssrcdialog.model.get(lyricssrcdialog.selectedIndex).name
            width: parent.width
            onClicked: { lyricssrcdialog.open(); }
        }

        Button
        {
            id: go
            text: "Go!"
            width: parent.width
        }
    }


    SelectionDialog
    {
        id: lyricssrcdialog
        titleText: "Download source"
        selectedIndex: 0
        model: ListModel
        {
            ListElement { name: "AZLyrics" }
        }
    }

}

I'm getting
Code:

.../main.qml:53 ReferenceError: Can't find variable fontcolor
.../main.qml:45 ReferenceError: Can't find variable fontcolor

What am I doing wrong?

ajalkane 2012-07-03 06:55

Re: QML and SelectionDialog
 
Quote:

Originally Posted by marmistrz (Post 1229083)
With this code:
[CODE]
I'm getting
Code:

.../main.qml:53 ReferenceError: Can't find variable fontcolor
.../main.qml:45 ReferenceError: Can't find variable fontcolor

What am I doing wrong?

I think you can't have property declarations anywhere else than the root item. So try to move 'property color fontcolor: "white"' under Item.

marmistrz 2012-07-03 11:25

Re: QML and SelectionDialog
 
Quote:

Originally Posted by ajalkane (Post 1230491)
I think you can't have property declarations anywhere else than the root item. So try to move 'property color fontcolor: "white"' under Item.

That way there are no errors, but still somehow only blank screen is painted..

ajalkane 2012-07-03 11:53

Re: QML and SelectionDialog
 
Quote:

Originally Posted by marmistrz (Post 1230665)
That way there are no errors, but still somehow only blank screen is painted..

That's another problem then. In those kind of situations, I've found it useful to put up a minimal working page (say one component). Then start adding stuff until you've isolated the problem.

marmistrz 2012-07-03 12:08

Re: QML and SelectionDialog
 
Quote:

Originally Posted by ajalkane (Post 1230705)
That's another problem then. In those kind of situations, I've found it useful to put up a minimal working page (say one component). Then start adding stuff until you've isolated the problem.

Wait... Does Item require x,y coordinates? It may be why it's a blank screen. As putting any component in a Rectangle caused not showing up of this component.


All times are GMT. The time now is 00:04.

vBulletin® Version 3.8.8