Re: [SailfishDevel] connect gridview on delegates click signal

2013-11-22 Thread Franck Routier (perso)
Hi,

This worked. I also had to stop using variant as a type (I also did read
the doc, which helps :-) ), and instead used basic types to directly
passed the needed values.

Thanks a lot.

Franck


Le 22/11/2013 03:18, Bea Lam a écrit :
 Hi Franck,
 
 To get a reference to a particular instance of a delegate, just give the 
 delegate an id, and references to that id from within the delegate 
 declaration will refer to that instance only. The “this” keyword is not valid 
 in this context. (See 
 http://qt-project.org/doc/qt-5.0/qtqml/qtqml-javascript-hostenvironment.html.)
 
 E.g.
 
 GridView {
   // …
 
   delegate: Card {
   id: cardDelegate
   onClicked: console.log(“You clicked:”, cardDelegate)
   }
 }
 
 If you click different cards in the view, you’ll see that each click prints 
 out a reference to a different Card object.
 
 Though, if you only need to pass on some data from the model — for example, 
 the “ico” or “val” properties — it’s probably better to pass those details 
 instead of the Card delegate instance itself, as the GridView creates and 
 destroys its delegate instances as necessary when the view is scrolled. 
 However, this may not be a concern in your case if you are simply pushing 
 another page onto the stack at this point, and not changing the state of the 
 GridView.
 
 cheers,
 
 Bea
 ___
 SailfishOS.org Devel mailing list
 

___
SailfishOS.org Devel mailing list


Re: [SailfishDevel] connect gridview on delegates click signal

2013-11-21 Thread Franck Routier (perso)
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Thanks for your tips, and sorry for the lte reply.


Le 18/10/2013 12:50, Matt Austin a écrit :

 
 I think you should be able to get what you're after with the
 following - assuming you have a reference to your 'detail page'
 (lets call it 'detailPage'):

That's the point. How do I get a reference to my detail page in my
grid page ?
I guess I should instanciate it in some way... maybe using a Loader ?

Here is what I tried:

GridView {
id: gridView
anchors.fill: parent
cellHeight: 150
cellWidth:110

model: ListModel {
ListElement {
ico: qrc:///card1.png
val: 1
}
ListElement {
ico: qrc:///card2.png
val: 2
}
}

Loader { id: pageLoader }

header: PageHeader {
title: Choose your card !
}
delegate: Card {
source: ico
value: val
onClicked: {
pageLoader.source = CardPage.qml
pageLoader.item.currentCard = this
pageStack.push(pageLoader.item)
}
}
}

with CardPage defined like this:

Page {
id: page
property variant currentCard

Column {
width: page.width
spacing: Theme.paddingLarge
PageHeader {
title: Your card !
}

Card {
source: currentCard.source
value: currentCard.value
}
}
}


I get the CardPage to be displayed, but then references to currentCard
are undefined. Maybe I shouldn't be using 'this' keyword ?

Or is there a better way to have a shared object to let my page
communicate ?

Thanks in advance,

Franck
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.14 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJSjgemAAoJEGEvoAir78RosRsH/1geVAWzTlaajeWyMapZUU+o
GeDYg0uE91a7WM4iaFFHtmLOeIvTIXYZN3VuWqhDxJKNy5vgg0Oj87VjLLGxQIMl
54k0S3gF9rJx2nb0YW5sip7FXM+voM/bKeswuuvEyJaJ5CaArhei4gr2Khy24ZRh
DSLj9TmB6+YL3S8HFE8igPo6U+I6ND7VkWgxuenwMWZF9GKqou6NLLvn8fpAyESn
jdMgETXWLJ/gQeQNw/WPabn28b1SGZj4rRZWLU4tEKDk30hf/Y6TN3rJ2Def8usL
stouaLWmwHFT36Ek9889Qgee7Zpq1uG0/DMQPPr2sGGLqev+JcCT6EJtjhPkYp8=
=8yHw
-END PGP SIGNATURE-
___
SailfishOS.org Devel mailing list

[SailfishDevel] connect gridview on delegates click signal

2013-10-18 Thread Franck Routier (perso)

Hi,

Firstly, I am really just trying to learn Qt, and I am not sure it is 
specific enough to be asked here, if not just tell me...


Anyway, I am using SailfishGridView (but it must be the same with 
standard GridView), with a ListModel, and a delegate component, in Qt Quick.

What I want to achieve is just this:
- display a page with a list of items (cards)
- when the user clicks on an item, display another page with the detail 
of the item


So, technically, I would like to connect the GridView to the onClicked 
signal of the delegates, and have a reference to the specific delegate 
that issued the signal (to be able to push another page, with the context).

I tried two approaches:
1) try to connect the gridview to the signal, but I don't have any 
handle/reference to the delegates. I could do this
2) create a function in the gridview, and call it in the delegate 
onClicked handler. But then, I could find a way the pass a reference to 
the delegate (using this keyword resulted in an undefined variable).


Thanks for any pointer.

Franck



smime.p7s
Description: Signature cryptographique S/MIME
___
SailfishOS.org Devel mailing list