Results 1 to 3 of 3

Thread: How to populate delegate with model data.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2008
    Posts
    89
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    1

    Default How to populate delegate with model data.

    Hi,

    I have a class ComboBoxDelegate derived from QItemDelegate
    I have a model class 'FrequencyRangeModel' derived from QAbstractProxyModel
    I have a BandPlanning for UI which contains both ComboBoxDelegate and FrequencyRangeModel as members.

    BandPlanning has a QTableView which is using ComboBoxDelegate to show combobox in each table cell.
    My requirement is that i need to populate each combo cell with the data from the model FrequencyRangeModel.
    How can i do it.

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    6
    Thanked 163 Times in 151 Posts

    Default Re: How to populate delegate with model data.

    Create a QComboBox in QItemDelegate::createEditor() and call QComboBox::setModel() on it with your model?

    HTH

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: How to populate delegate with model data.

    As far as I understand, you are showing a list of items for a particular cell/index/row-col . Am I right ?

    In that case you will need to store the list in model. You can use QModelIndex::internalPointer to store whatever data u want and populate the combo box from the pointer returned by internalPointer. In the delegate function, you are passed a QModelIndex.
    You may refer Simple Tree Model or Simple DOM Model example in Qt Demo on how they use internalPointer .
    Hope this helps

Similar Threads

  1. Clearing data model
    By db in forum Newbie
    Replies: 6
    Last Post: 16th February 2008, 14:10
  2. Model - data
    By gyre in forum Newbie
    Replies: 1
    Last Post: 9th December 2007, 20:49
  3. Data model
    By steg90 in forum Qt Programming
    Replies: 3
    Last Post: 17th September 2007, 13:14
  4. Custom Model Class
    By mattjgalloway in forum Qt Programming
    Replies: 12
    Last Post: 4th June 2007, 18:30
  5. Informing a model its data has changed
    By saknopper in forum Newbie
    Replies: 3
    Last Post: 17th January 2007, 20:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.