Results 1 to 3 of 3

Thread: jump to index in QDataWidgetMapper that uses QSqlTableModel

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default jump to index in QDataWidgetMapper that uses QSqlTableModel

    I am using a table with QDataWidgetMapper and QSqlTableModel.
    To 'jump' to a particular record, I'm using a QCompleter with QStandardItemModel.
    The table contains the fields UnitName and LastName (among others). The QCompleter uses UnitName as the completion field. This all works great, i.e. I can jump to the selected record as follows:

    Qt Code:
    1. //lineEdit 'jump' button <enter> pressed
    2. void MainWindow::on_le_jump_returnPressed()
    3. {
    4. QModelIndex indx = completer->currentIndex();
    5. if (!indx.isValid())
    6. qDebug() << "is null";
    7.  
    8. //column 0 is the unit name, column 1 is the record index
    9. mapper->setCurrentIndex(completer->currentIndex().sibling(0,1).data().toInt());
    10. ui->le_jump->clear();
    11. }
    To copy to clipboard, switch view to plain text mode 

    I'm trying to add a dialog where the user can search by (partial) LastName match. I am able to use the following sql:

    Qt Code:
    1. SELECT LastName, UnitName, UnitID FROM unit WHERE LastName LIKE '%%%1%%'
    To copy to clipboard, switch view to plain text mode 

    This query will result in 0 or more matches which are displayed in a QTreeWidget. The user then clicks on one of the rows and this is where I get stuck... How do I now 'jump' to the unit that was just selected?
    I tried to use the QCompleter model's match method but I'm not sure if that's the right approach.

    I was thinking to set the filter on the mapper but that only works partially, i.e. it selects the correct unit but since the mapper is now filtered, my 'jump to unit' line edit isn't working anymore... I guess I need to clear the filter, but how?

    <added a bit later>
    I like answering my own question... I simply clear the filter when I use the completer again in the 'jump to unit' line edit -> problem solved.

    However, what do you think of my approach? Is there a more elegant solution?
    Last edited by schnitzel; 11th June 2011 at 22:19.

Similar Threads

  1. Replies: 0
    Last Post: 17th October 2010, 12:53
  2. Replies: 3
    Last Post: 4th October 2010, 03:57
  3. Replies: 1
    Last Post: 4th October 2010, 00:46
  4. QDataWidgetMapper setting own model index
    By AlGaN in forum Qt Programming
    Replies: 0
    Last Post: 16th February 2010, 16:34
  5. Replies: 3
    Last Post: 31st March 2008, 21:23

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.