Results 1 to 5 of 5

Thread: QDataWidgetMapper to synchronize widgets with QTableView

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2007
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QDataWidgetMapper to synchronize widgets with QTableView

    I have always been very happy with Qt's documentation, but when I tried to use QDataWidgetMapper I was a bit disappointed. Is this just supposed to work by magic? It doesn't do that here...

    I have a QTableView with a QAbstractTableModel derived vertical model with four columns. This works very nicely and I can view and edit rows in the table view.
    I also have a dock widget with some line edits as an alternative way to edit the fields. These fields are the one I have used a QDataWidgetMapper for. The problem is just that it doesn't work. When I select a row and edit it in the dock window, the table is updated, but not the other way around. The fields in the dock widget aren't filled at all when I change the selected row in the table view. *Something* is happening when I change the select row though, because when I submit the text from the dock widget edits the correct row is updated.

    The code:
    Qt Code:
    1. mapper = new QDataWidgetMapper();
    2. mapper->setModel(model);
    3. mapper->addMapping(lineEdit1, 0);
    4. mapper->addMapping(lineEdit2, 1);
    5.  
    6. connect(view->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), mapper, SLOT(setCurrentModelIndex(QModelIndex)));
    To copy to clipboard, switch view to plain text mode 

    view is a pointer to the table view, model is a painter to the model I use.

    What did I forget to do?
    Last edited by ehamberg; 20th February 2008 at 22:58.

Similar Threads

  1. QTableView with widgets
    By steg90 in forum Qt Programming
    Replies: 5
    Last Post: 22nd November 2007, 10:46

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.