Results 1 to 2 of 2

Thread: Depending Combobox

  1. #1
    Join Date
    Oct 2009
    Posts
    65
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Depending Combobox

    GoodMorning to all,
    I've a problem perhaps easy to solve, but I don't know how

    This is my problem: I've a Dialog that create a record for a Custromers table, and I've 3 tables in my db for Countries, City, and Zip codes.
    I've create my Dialog with QDataWidgetMapper and QSqlRelationalTableModel and three relations for the table above, now, I got three QCombobox filled by data but... not filtered! I'd like that the QComboBox City show only the city relative to the Country selected on the precedings QComboBox (my table had 3 different Foreign keys for the 3 tables, so 3 relations isn't it?).

    I can connect the currentIndexChanged(int) of the first QCombobox to a Slot that filter the model of the second one, but... when I use the QDataWidgetMapper to modify one element, this event don't fire so it doesn't work.

    Where I got a mistake? How can I got what I search?

    Thanks a lot for your time

    Michele

  2. #2
    Join Date
    Oct 2009
    Posts
    65
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Depending Combobox

    Hello to everybody,
    To solve this problem, i trying to subclass a QSqlRelationalDelegate, so that, at che column of second combobox, I can apply a filter on the QSqlTableModel returned by relationalModel; but i can't do this, because the delegate use only a const QModelIndex so i can't access the complete model and use the setFilter method. This is my code:
    Qt Code:
    1. void setEditorData(QWidget *editor, const QModelIndex &index) const
    2. {
    3. switch(index.column()) {
    4. case 4:{
    5. const QSqlRelationalTableModel * sqlModel = qobject_cast<const QSqlRelationalTableModel *>(index.model());
    6. sqlModel->setFilter(QString("CodProvincia=%1").arg(sqlModel->index(index.row,10).data().toInt());
    7. QComboBox * combo = qobject_cast<QComboBox *> (editor);
    8. if (!sqlModel || !combo){
    9. QItemDelegate::setEditorData(editor,index);
    10. return;
    11. }
    12. combo->setCurrentIndex(combo->findText(sqlModel->data(index).toString()));
    13. break;}
    To copy to clipboard, switch view to plain text mode 

    But it return an error, because the index is only a constant. This is the error:
    ..\picloaddelegate.h:24: error: passing 'const QSqlRelationalTableModel' as 'this' argument of 'virtual void QSqlTableModel::setFilter(const QString&)' discards qualifiers
    Any ideas of how resolve it?

    thanks a lot for your time!

    Michele

Similar Threads

  1. how to get font width depending on its scale
    By iceman in forum Qt Programming
    Replies: 0
    Last Post: 28th July 2010, 06:50
  2. Resizing window depending on QTableView
    By Ferric in forum Newbie
    Replies: 2
    Last Post: 9th February 2010, 04:17
  3. dynamically chaging font depending on resolution..
    By Neeraj19 in forum Qt Programming
    Replies: 1
    Last Post: 1st October 2008, 11:09
  4. Table with number of columns depending on row?
    By Arghargh in forum Qt Programming
    Replies: 3
    Last Post: 29th May 2008, 13:03
  5. Displaying windows depending on checkboxes
    By Salazaar in forum Newbie
    Replies: 1
    Last Post: 12th May 2007, 19:42

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.