Results 1 to 4 of 4

Thread: QAbstractProxyModel and "virtual" columns

  1. #1
    Join Date
    Aug 2006
    Location
    Some where in Argentina
    Posts
    23
    Thanks
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question QAbstractProxyModel and "virtual" columns

    Can reimplement QAbstractProxyModel to add a new column that needs to be calculated?

    The specific case is that I have a model that has the product, qty and price and need to add a new column with the value (price*qty).
    Can I use QAbstractProxyModel to add that column, reimplementing all the functions that are necesaries?

    If there is another way to do it?

    thanks in advance

  2. #2
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QAbstractProxyModel and "virtual" columns

    Absolutely. You can do it that way. Just reimplement all the abstract methods from QAbstractItemModel. Of special interest to you are the columnCount() and data() functions.

    However, if you can, you might want to just add that column to the original model, and only use a proxy if you want to filter it out somewhere. Would be easier to program, I think.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  3. The following user says thank you to Michiel for this useful post:

    tranfuga25s (15th July 2007)

  4. #3
    Join Date
    Aug 2006
    Location
    Some where in Argentina
    Posts
    23
    Thanks
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QAbstractProxyModel and "virtual" columns

    Another question:

    How can I now when a item is updated from the QTableView itself, not the model?
    I need to update a field to total outside the tableview but cant find a suitable signal to connect to a slot...

    I`m not reimplementing any method for my view...

    Thanks again!

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QAbstractProxyModel and "virtual" columns

    When an item is edited in a view, the view updates the model which in turn emits the dataChanged() signal. So if you want to update something which is not part of the model, connect to that signal. If you want to update some other item that is part of the model, I suggest you do that from within setData() reimplementation.

  6. The following user says thank you to wysota for this useful post:

    tranfuga25s (15th July 2007)

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.