Qt-interest Archive, October 2006
Re: QComboBox, setModel()
Message 1 in thread
sorry, I meant to say "use a custom model"
any takers?
On 9/28/06, Patrick Stinson <patrickkidd.lists@xxxxxxxxx> wrote:
> I have set a combobox to use a custom mode, but it does not display
> the string (Qt::DisplayRole) for the current selection. When I click
> on the combobox I can see all of the values of the selection.
>
> Is there something else I have to do?
>
> --
> Patrick Kidd Stinson
> http://www.patrickkidd.com/
> http://pkaudio.sourceforge.net/
> http://pksampler.sourceforge.net/
>
--
[ signature omitted ]
Message 2 in thread
Patrick Stinson wrote:
> sorry, I meant to say "use a custom model"
>
> any takers?
>
> On 9/28/06, Patrick Stinson <patrickkidd.lists@xxxxxxxxx> wrote:
>> I have set a combobox to use a custom mode, but it does not display
>> the string (Qt::DisplayRole) for the current selection. When I click
>> on the combobox I can see all of the values of the selection.
>>
>> Is there something else I have to do?
>>
>> --
>> Patrick Kidd Stinson
>> http://www.patrickkidd.com/
>> http://pkaudio.sourceforge.net/
>> http://pksampler.sourceforge.net/
>>
>
>
Hi Patrick,
I guess you have created your own model. Now, if you have not done, you
need to reimplement its data() method. The catch here is that you need
to also act upon the Qt::EditRole role, even if you have reimplemented
the flags() method on your model to not return a Qt::ItemIsEditable
state and even if you have explicitly set your combobox to not be
editable (combo->setEditable(false)). You have to do in your data()
method something like:
if ( role == Qt::DisplayRole || role == Qt::EditRole ) {
// Return here your own item
QString item = customItemList->getItem( index.row() );
return QVariant(item);
} else {
return QVariant();
}
This will provide you with the functionality of a normal combobox, at
least as far as I can tell so far.
I hope this helps,
stathis
--
[ signature omitted ]
Message 3 in thread
yeah, that's it. thanks!
On 10/3/06, Stathis <stathis@xxxxxxxxxxxxxxxx> wrote:
> Patrick Stinson wrote:
> > sorry, I meant to say "use a custom model"
> >
> > any takers?
> >
> > On 9/28/06, Patrick Stinson <patrickkidd.lists@xxxxxxxxx> wrote:
> >> I have set a combobox to use a custom mode, but it does not display
> >> the string (Qt::DisplayRole) for the current selection. When I click
> >> on the combobox I can see all of the values of the selection.
> >>
> >> Is there something else I have to do?
> >>
> >> --
> >> Patrick Kidd Stinson
> >> http://www.patrickkidd.com/
> >> http://pkaudio.sourceforge.net/
> >> http://pksampler.sourceforge.net/
> >>
> >
> >
>
> Hi Patrick,
>
> I guess you have created your own model. Now, if you have not done, you
> need to reimplement its data() method. The catch here is that you need
> to also act upon the Qt::EditRole role, even if you have reimplemented
> the flags() method on your model to not return a Qt::ItemIsEditable
> state and even if you have explicitly set your combobox to not be
> editable (combo->setEditable(false)). You have to do in your data()
> method something like:
>
>
> if ( role == Qt::DisplayRole || role == Qt::EditRole ) {
>
> // Return here your own item
> QString item = customItemList->getItem( index.row() );
>
> return QVariant(item);
> } else {
> return QVariant();
> }
>
> This will provide you with the functionality of a normal combobox, at
> least as far as I can tell so far.
>
> I hope this helps,
> stathis
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]