Results 1 to 3 of 3

Thread: Filter relation column options - QSqlRelationalDelegate? constrain or restrict option

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2011
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Filter relation column options - QSqlRelationalDelegate? constrain or restrict option

    qt4.8

    I have a relational table model, with editable relations that work.

    The table is filtered, and the default relational delegate
    collects all possible values from the database as combo options.

    I would like to restrict the available options to either:

    a) the option set defined by the table's filter - i.e. what's available in the current table
    OR
    b) manually-generated list (of relations in the current table )

    either one will do.

    I attempted a specialized createEditor function to
    create an editor with a fixed/generated set of options.

    Qt Code:
    1. QWidget *TeamSelectDelegate::createEditor(QWidget *parent,
    2. const QStyleOptionViewItem & option,
    3. const QModelIndex & index) const
    4. {
    5. Q_UNUSED(option);
    6. const QSqlRelationalTableModel *sqlModel = qobject_cast<const QSqlRelationalTableModel *>(index.model());
    7. QSqlTableModel *childModel = sqlModel ? sqlModel->relationModel(index.column()) : 0;
    8. if (!childModel)
    9. return QItemDelegate::createEditor(parent, option, index);
    10.  
    11. QComboBox *combo = new QComboBox(parent);
    12. combo->setDuplicatesEnabled(false);
    13. combo->setModel(childModel);
    14. combo->setModelColumn(childModel->fieldIndex(sqlModel->relation(index.column()).displayColumn()));
    15.  
    16. combo->clear(); // get rid of stuff from model,
    17. combo->addItems(*_relevant_teams); // and put in options from a subset ( generated list )
    18.  
    19. combo->installEventFilter(const_cast<TeamSelectDelegate *>(this));
    20. return combo;
    To copy to clipboard, switch view to plain text mode 

    "_relevant_teams" is a previously generated list of options.
    This did not work... it seemed to delete all items in the DB!

    Thanks for sharing your ideas.


    Cheers!
    mike
    Last edited by talkfig; 1st May 2012 at 23:18.

Similar Threads

  1. How to set filter option in QTableWidget
    By johnMick in forum Newbie
    Replies: 7
    Last Post: 18th October 2011, 14:41
  2. Multiple axes with a relation
    By pkj in forum Qwt
    Replies: 1
    Last Post: 21st February 2011, 06:46
  3. QSqlRelationalDelegate
    By pippo42 in forum Qt Programming
    Replies: 1
    Last Post: 2nd May 2010, 12:05
  4. Tree different column counts by row- options?
    By LynneV in forum Qt Programming
    Replies: 0
    Last Post: 8th April 2010, 17:47
  5. QComboBox QSqlQueryModel & relation.
    By matheww in forum Qt Programming
    Replies: 2
    Last Post: 20th June 2007, 04:56

Tags for this Thread

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.