Results 1 to 5 of 5

Thread: Value changed in a QTableView field

  1. #1
    Join Date
    Jun 2009
    Posts
    8
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Value changed in a QTableView field

    I've searched a bit, but could not found how to do this.

    Have got a QSqlTableModel and a QTableView which I use to show the data.
    I would like to know if, when I change the value of a field in QTableView, a signal is emitted, because I need to call a function when the user edit a field.

    Don't care, now, to change the data directly in database, I'll do the commit manually.

  2. #2
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Value changed in a QTableView field

    I never used QSqlTableModel, but as far as QTableView if you want users to edit data I think you should use QTableWidget instead. Assuming you're using QTCreator just right clik on QTableWidget choose 'Go to Slot... ' option, and a list with Signal will apear. I think QTableWidget::itemChanged ( QTableWidgetItem * item ) will do.

  3. #3
    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: Value changed in a QTableView field

    For every model the QAbstractItemModel::dataChanged() signal is emitted when contents of the model change. So simply go through QAbstractItemView::model() to find the appropriate signal and connect to it.
    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.


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

    nittalope (12th August 2009)

  5. #4
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Value changed in a QTableView field

    Quote Originally Posted by john_god View Post
    I never used QSqlTableModel, but as far as QTableView if you want users to edit data I think you should use QTableWidget instead.
    Just a remark here: QTableWidget is basically a QTableModel a filter and a QTableView put into one convenience widget. When the model supports data for the Qt::EditRole, then QTableView will be perfectly able to support editing of data.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  6. #5
    Join Date
    Jun 2009
    Posts
    8
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Value changed in a QTableView field

    @wysota:
    thank you! that was what I was looking for!

    @john_god:
    franz is right, no problem at all editing data in QTableView!

    By the way here is how I solved it:

    Qt Code:
    1. myModel = new QSqlRelationalTableModel(this);
    2.  
    3. connect(myModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(myFunction()));
    To copy to clipboard, switch view to plain text mode 

    and then I implemented myFunction() to do what I need to do

Similar Threads

  1. boolean field checkbox QTableView
    By skuda in forum Qt Programming
    Replies: 4
    Last Post: 8th November 2010, 13:48
  2. Replies: 1
    Last Post: 10th June 2009, 21:59
  3. Some very weird compilation warnings
    By MarkoSan in forum Qt Programming
    Replies: 21
    Last Post: 23rd January 2008, 16:48
  4. How to know when field is edited within QTableView
    By dkite in forum Qt Programming
    Replies: 3
    Last Post: 1st January 2007, 18:51
  5. Replies: 9
    Last Post: 23rd November 2006, 11:39

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.