[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] QComboBox: display text but pass on Unique Id (MySql)
From:       Cristobal Infante <cgcris () gmail ! com>
Date:       2011-11-18 22:50:06
Message-ID: CAL3mZ3gBcxfnViWSsVCS+JUyUK4Tk6ryG7VAtBxNVAaHkWpBsw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


ok got the answer:

        uniqueIdColumn = 0
        uniqueId =
model.data(model.createIndex(Index,uniqueIdColumn,0),QtCore.Qt.DisplayRole)

I am working with python 2.7 so had to set the API v2...

import sip
sip.setapi('QVariant', 2)



On 16 November 2011 22:44, Cristobal Infante <cgcris@gmail.com> wrote:

> I havent found the soultion for this yet, it's driving me a bit mad
>
> can somebody please answer me this "simple" question:
>
> How do you retrieve a single value from a model if you know the index?
>
> Thanks, Cris
>
>
> On 8 November 2011 22:38, David Boddie <david@boddie.org.uk> wrote:
>
>> On Fri, 4 Nov 2011 13:51:45 +0000, Cristobal Infante wrote:
>>
>> > My first post in this list, a big hello to everyone :D
>>
>> Welcome!
>>
>> > I am just starting with Pyqt but have enough experience with python.
>> >
>> > I am connecting a Mysql Databse nicely, being able to retrieve the
>> complete
>> > table and
>> > get it as a model. I've then been able to display in a combobox a "Name"
>> > column
>> > just by using 'setcolumn(1).
>>
>> OK. So far so good.
>>
>> > Until here is all good, but is passing the Id from that record that's
>> > proven hard to crack for me.
>> > I've been looking around in the net, but havent been able to find an
>> > example using a database.
>> > So display "Jane" put pass on the unique ID of that record.
>>
>> Just an idea: is the record() method of the model what you want? The model
>> should inherit this from QSqlQueryModel.record().
>>
>> > I have an 'activated' function that is being executed everytime the
>> combo
>> > changes, but at the moment it's only retrieving
>> > info from that column that's displayed in the combobox.
>>
>> You can get the corresponding row of the item displayed in the combo box
>> by calling the QComboBox.currentIndex() method. This is effectively the
>> same as the row in the model, anyway. Then pass it to the model's record()
>> method and see what you get.
>>
>> Does that work?
>>
>> David
>> _______________________________________________
>> PyQt mailing list    PyQt@riverbankcomputing.com
>> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>
>
>

[Attachment #5 (text/html)]

ok got the answer:<div><br></div><div><div>        uniqueIdColumn = 0</div><div>      \
uniqueId = model.data(model.createIndex(Index,uniqueIdColumn,0),QtCore.Qt.DisplayRole)</div><div><br></div><div>I \
am working with python 2.7 so had to set the API v2...</div> \
<div><br></div><div><div>import sip</div><div>sip.setapi(&#39;QVariant&#39;, \
2)</div></div><div><br></div><div><br></div><br><div class="gmail_quote">On 16 \
November 2011 22:44, Cristobal Infante <span dir="ltr">&lt;<a \
href="mailto:cgcris@gmail.com">cgcris@gmail.com</a>&gt;</span> wrote:<br> <blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex;">I havent found the soultion for this yet, it&#39;s driving \
me a bit mad<div><br></div><div>can somebody please answer me this &quot;simple&quot; \
question:</div> <div><br></div><div>How do you retrieve a single value from a model \
if you know the index? </div> <div><br></div><div>Thanks, Cris</div><div \
class="HOEnZb"><div class="h5"><div><br><br><div class="gmail_quote">On 8 November \
2011 22:38, David Boddie <span dir="ltr">&lt;<a href="mailto:david@boddie.org.uk" \
target="_blank">david@boddie.org.uk</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"> <div>On Fri, 4 Nov 2011 13:51:45 +0000, Cristobal Infante \
wrote:<br> <br>
&gt; My first post in this list, a big hello to everyone :D<br>
<br>
</div>Welcome!<br>
<div><br>
&gt; I am just starting with Pyqt but have enough experience with python.<br>
&gt;<br>
&gt; I am connecting a Mysql Databse nicely, being able to retrieve the complete<br>
&gt; table and<br>
&gt; get it as a model. I&#39;ve then been able to display in a combobox a \
&quot;Name&quot;<br> &gt; column<br>
&gt; just by using &#39;setcolumn(1).<br>
<br>
</div>OK. So far so good.<br>
<div><br>
&gt; Until here is all good, but is passing the Id from that record that&#39;s<br>
&gt; proven hard to crack for me.<br>
&gt; I&#39;ve been looking around in the net, but havent been able to find an<br>
&gt; example using a database.<br>
&gt; So display &quot;Jane&quot; put pass on the unique ID of that record.<br>
<br>
</div>Just an idea: is the record() method of the model what you want? The model<br>
should inherit this from QSqlQueryModel.record().<br>
<div><br>
&gt; I have an &#39;activated&#39; function that is being executed everytime the \
combo<br> &gt; changes, but at the moment it&#39;s only retrieving<br>
&gt; info from that column that&#39;s displayed in the combobox.<br>
<br>
</div>You can get the corresponding row of the item displayed in the combo box<br>
by calling the QComboBox.currentIndex() method. This is effectively the<br>
same as the row in the model, anyway. Then pass it to the model&#39;s record()<br>
method and see what you get.<br>
<br>
Does that work?<br>
<span><font color="#888888"><br>
David<br>
</font></span><div><div>_______________________________________________<br>
PyQt mailing list    <a href="mailto:PyQt@riverbankcomputing.com" \
target="_blank">PyQt@riverbankcomputing.com</a><br> <a \
href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" \
target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br> \
</div></div></blockquote></div><br> </div>
</div></div></blockquote></div><br></div>



_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic