Results 1 to 15 of 15

Thread: Sharing Selections between Model and ProxyModel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Sharing Selections between Model and ProxyModel

    The example is very simple and only illustrates the way of handling things. To implement features you want, you'd probably have to reimplement setData() and connect proper signals and slots so that changes propagate between models.

  2. #2
    Join Date
    Nov 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Sharing Selections between Model and ProxyModel

    By reimplementing setData() in the proxy model, I managed to get changes in the proxy model to be reflected by in the original model.

    However, I am still having a slight problem keeping the proxy in sync with the original model. For example, if I changed row 1, column 1, from "1" (the original value) to "A", the proxy model's view is not updated until I do something like move the scroll bar or something else that generates events or signals.

    Which signal should I connect to which slot (and which object)?

  3. #3
    Join Date
    Jan 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Sharing Selections between Model and ProxyModel

    The transpose proxy code (http://wiki.qtcentre.org/index.php?t...se_Proxy_Model) works fine but only with quadratic models where there are the same number of rows and columns. If there are e.g. more columns than rows the data() function is not called for all cells that it needs to be called for. Is there anyone who knows how to implement this transpose with a on-quadratic model?

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

    Default Re: Sharing Selections between Model and ProxyModel

    The model is broken, it was just an example. But it should work for non-square models too, I don't see what would prevent it from that. The only two things that are not in the model is reacting to changes in the source model and handling hierarchical source models. Apart from that the example is fully functional.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Sharing Selections between Model and ProxyModel

    It does not work for non-square models since the data-functions is not called enough number of times if there is e.g. more columns than rows

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

    Default Re: Sharing Selections between Model and ProxyModel

    You are wrong, I just checked it. The model works fine for non-square models.

    Qt Code:
    1. int main(int argc, char **argv){
    2. QApplication app(argc, argv);
    3. QStandardItemModel model(3,5);
    4. for(int i=0;i<5;i++)
    5. for(int j=0;j<3;j++){
    6. model.setData(model.index(j,i), qrand()%20);
    7. }
    8. v1.setModel(&model);
    9. TransposeProxyModel proxy;
    10. proxy.setSourceModel(&model);
    11. v2.setModel(&proxy);
    12. v1.show();
    13. v2.show();
    14. return app.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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.