Results 1 to 4 of 4

Thread: How to use a different model in a delegate in a model-view construction

  1. #1
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default How to use a different model in a delegate in a model-view construction

    Hello all, I hope you can help me with this.

    The situation is as follows: I have two widgets, a listView and a tableView. Both have their own models (listmodel and tablemodel - the data is not really related).
    The listView is based on a QStringList filled with options, the user can add and remove as well.
    The tableview shows the content of a file. The headers of its columns should all be comboboxes, in which you select which option from the listView is applicable to the column beneath it.

    Is there an elegant/proper way to set the listmodel as the model for my ComboboxDelegates? Or is there perhaps a way to have a third model for the ComboBoxDelegates which synchronizes with the listmodel in real time?

    Any help is appreciated.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to use a different model in a delegate in a model-view construction

    QComboBox has a method called setModel()
    Call that with your list model.

    Cheers,
    _

  3. #3
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to use a different model in a delegate in a model-view construction

    Thanks for your reply.

    The problem is that the QComboBox is a delegate of my tableView, and it doesn't know the listmodel at all! The tableView has its own model, the tablemodel. The listmodel is created when the ui is constructed.

    Here's a picture to clarify what I mean:

    problem.png

    My UI class creates the models and attaches them to the views. The TableModel class is responsible for the data inside the table, including the ComboBoxDelegates. And those have no connection with the listView's listmodel at this point. If I want to set the model for those comboboxes, the code doesn't compile (error: a nonstatic member reference must be relative to a specific object) - the model is dynamic.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to use a different model in a delegate in a model-view construction

    Quote Originally Posted by Meladi View Post
    The listmodel is created when the ui is constructed.
    At which point you probably have access to the list model, no?
    I.e. pass it to the delegate's constructor or have a method like setComboBoxModel(...)

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    Meladi (10th February 2014)

Similar Threads

  1. model view delegate
    By waiter in forum Qt Programming
    Replies: 1
    Last Post: 11th May 2012, 07:21
  2. Qt delegate model data and view
    By giusepped in forum Qt Programming
    Replies: 0
    Last Post: 27th July 2011, 11:30
  3. Model/View/Delegate How gets setEditorData / setModelData
    By moviemax in forum Qt Programming
    Replies: 0
    Last Post: 11th July 2011, 11:29
  4. Model-View-Delegate
    By hotdox in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2010, 13:20
  5. Model View - Delegate - setIndexWidget
    By starcontrol in forum Qt Programming
    Replies: 16
    Last Post: 2nd April 2008, 14:30

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.