Results 1 to 4 of 4

Thread: Sinchronize a QTableView with a QDataWidgetMapper (sharing the same model)

  1. #1
    Join Date
    Jan 2013
    Posts
    43
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    27
    Thanked 6 Times in 5 Posts

    Default Sinchronize a QTableView with a QDataWidgetMapper (sharing the same model)

    Hi,
    I have a QTableView and a QDataWidgetMapper that share the same model (QSqlTableModel).

    This code allows sinchronization when i click on the table:
    Qt Code:
    1. connect(view->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), mapper, SLOT(setCurrentModelIndex(QModelIndex)));
    To copy to clipboard, switch view to plain text mode 

    What is the equivalent connect to use when changing the current index in the QDataWidgetMapper???

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Sinchronize a QTableView with a QDataWidgetMapper (sharing the same model)

    You connect a slot to the currentIndexChanged() of the mapper, use the passed int as a row in your table, let the model create a QModelIndex for that and call select and/or setCurrentIndex on the view's item selection model.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    aguleo (5th March 2014)

  4. #3
    Join Date
    Jan 2013
    Posts
    43
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    27
    Thanked 6 Times in 5 Posts

    Default Re: Sinchronize a QTableView with a QDataWidgetMapper (sharing the same model)

    I did that.
    I was just hopping for a more "autommatic" solution, like the one presented for the view.
    Any way ... it's working.
    Thanks

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Sinchronize a QTableView with a QDataWidgetMapper (sharing the same model)

    Yeah, it is strange. I was expecting an overloaded currentChangedSIgnal() signal with a QModelIndex, but I guess the problem is that the mapper always makes more than one "cell" current (all columns in that row it has widget mappings for).

    Cheers,
    _

Similar Threads

  1. QDataWidgetMapper doesn't respond to model changes
    By graffy in forum Qt Programming
    Replies: 0
    Last Post: 3rd January 2014, 10:37
  2. QDataWidgetMapper setting own model index
    By AlGaN in forum Qt Programming
    Replies: 0
    Last Post: 16th February 2010, 16:34
  3. Sharing Selections between Model and ProxyModel
    By mentat in forum Qt Programming
    Replies: 14
    Last Post: 27th January 2010, 17:31
  4. Replies: 3
    Last Post: 31st March 2008, 21:23
  5. Replies: 3
    Last Post: 21st January 2008, 12:22

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.