Results 1 to 8 of 8

Thread: How to notify QTableView of a modified CustomModel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2009
    Posts
    36
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1
    Thanked 7 Times in 6 Posts

    Default Re: How to notify QTableView of a modified CustomModel

    I think it was a great thing that you mentioned it! I didn't even know it existed until I looked at the recent Qt documentation for 4.6.x. I'm currently using 4.5.3, so I had to use the setModel, delete old model pointer method for my uses. But I'll be sure to use the new method you mentioned when I upgrade!

  2. #2
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    57
    Thanked 4 Times in 4 Posts

    Default Re: How to notify QTableView of a modified CustomModel

    Hi,

    I solved this kind of "situation" in a very "craft" way:

    Qt Code:
    1. ...
    2. Dialog::Dialog(QWidget *parent)
    3. : QDialog(parent), ui(new Ui::Dialog)
    4. {
    5. ui->setupUi(this);
    6. ui->fileNameLabel->setText("pessoa.png");
    7. model = new QSqlTableModel(this);
    8. setModel();
    9. setView();
    10. ...
    11. }
    12.  
    13. void Dialog::setModel()
    14. {
    15. model->setTable("photo");
    16. model->setHeaderData(photo_id, Qt::Horizontal, tr("ID"));
    17. model->setHeaderData(photo_name, Qt::Horizontal, trUtf8("Filename"));
    18. model->setHeaderData(photo_image, Qt::Horizontal, trUtf8("Image"));
    19. model->select();
    20. }
    21.  
    22. void Dialog::setView()
    23. {
    24. view = ui->tableView;
    25. view->setModel(model);
    26. view->setColumnHidden(photo_image, true);
    27. view->horizontalHeader()->setStretchLastSection(true);
    28. view->setSelectionMode(QAbstractItemView::SingleSelection);
    29. view->setSelectionBehavior(QAbstractItemView::SelectRows);
    30. }
    To copy to clipboard, switch view to plain text mode 

    This way i call setView() when i need to make sure that model and view are sinchronized.

Similar Threads

  1. how to implement QApplication.notify()
    By di_zou in forum Newbie
    Replies: 1
    Last Post: 15th February 2010, 18:12
  2. URL last modified
    By tsd-charlie in forum Qt Programming
    Replies: 1
    Last Post: 2nd October 2009, 15:09
  3. QApplication::notify()
    By jeffpogo in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2009, 22:46
  4. Reimplementing QApplication::notify( )
    By Rayven in forum Qt Programming
    Replies: 1
    Last Post: 15th May 2008, 17:22
  5. Qt web notify
    By bunjee in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 13:24

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.