Results 1 to 5 of 5

Thread: QTableView help

  1. #1
    Join Date
    Nov 2009
    Posts
    68
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded

    Default QTableView help

    I am using a QTableView to display a QSqlTableModel.
    Qt Code:
    1. ui->tableView->setModel(myTableModel);
    2. ui->tableView->show();
    To copy to clipboard, switch view to plain text mode 

    But when the user changes rows I want to get some information from the db and display it in a side widget. But in QTableView there is no signal that the row has been changed. I cannot use a QTableWiget because it will not "bind" to a QSqlTableModel...it says setModel() is private.

    So QTableWidget will give a signal when a row has changed positions but it will not bind to the QSqlTableModel.

    What is the best way to do this?

  2. #2
    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: QTableView help

    The signal is in the model - QAbstractItemModel::dataChanged().
    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.


  3. #3
    Join Date
    Nov 2009
    Posts
    68
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded

    Default Re: QTableView help

    That does not work. The only time I could get that signal to "fire" was when the contents of a cell changed. I want to know when a new row is "selected".

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTableView help

    Quote Originally Posted by weaver4 View Post
    I want to know when a new row is "selected".
    QAbstractItemView::selectionModel() and QItemSelectionModel::currentRowChanged().

  5. #5
    Join Date
    Nov 2009
    Posts
    68
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded

    Default

    I am new to this and I just don't understand how to set that up.

    Here is what I have now. But everytime I select a new row it crashes.

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(parent), ui(new Ui::MainWindow)
    3. {
    4.  
    5. ui->setupUi(this);
    6.  
    7. wrkTable = dbgmgr.OpenDB("moz_downloads","","downloads.sqlite");
    8.  
    9. if (wrkTable)
    10. {
    11. connect(wrkTable, SIGNAL(dataChanged(QModelIndex, QModelIndex)),
    12. this, SLOT(rowMoved(QModelIndex, QModelIndex)));
    13.  
    14. ui->tableView->setModel(wrkTable);
    15. ui->tableView->show();
    16. QItemSelectionModel sm(wrkTable);
    17. ui->tableView->setSelectionModel(&sm);
    18.  
    19. dbgmgr.DebugInfo(true);
    20. }
    21. else
    22. qDebug() << "Error: " << dbgmgr.error;
    23. }
    24.  
    25. void MainWindow::rowMoved(QModelIndex tl,QModelIndex br)
    26. {
    27. qDebug() << "Row Moved! ";
    28. }
    To copy to clipboard, switch view to plain text mode 

    I got it!

    Thanks
    Last edited by wysota; 24th November 2009 at 23:39.

Similar Threads

  1. QTableView empty space or too little space.
    By davemar in forum Qt Programming
    Replies: 2
    Last Post: 16th October 2009, 16:00
  2. One Model, Two Views (QTreeView and QTableView)
    By dgarrett97 in forum Newbie
    Replies: 2
    Last Post: 14th September 2009, 18:10
  3. Replies: 2
    Last Post: 7th June 2009, 10:47
  4. Replies: 3
    Last Post: 29th January 2009, 08:38
  5. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 13:49

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.