Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem displaying a column in a ProxyModel
Forum Updated to NodeBB v4.3 + New Features

Problem displaying a column in a ProxyModel

Scheduled Pinned Locked Moved General and Desktop
3 Posts 1 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    p91paul
    wrote on last edited by
    #1

    I've subclassed QSortFilterProxyModel and overridden the data() method to show two columns (name and surname) in a combobox as a single element.
    the combobox is mapped in a QWidgetMapper to edit a database.
    here's the problem: i select an element, then i click on another part of the window and my selection changes, and another element is selected automatically (it seems to be a random choice).

    here is the data() function:
    @
    QVariant MyProxyModel::data(const QModelIndex & index,int role) const{
    if (index.column()==1 && role==Qt::DisplayRole){
    QModelIndex name = mapToSource(index);
    QModelIndex surname = name.sibling(name.row(),name.column()+1);
    return (sourceModel()->data(name).toString()+" "+
    sourceModel()->data(surname).toString()).trimmed();
    }
    else return QSortFilterProxyModel::data(index,role);

    }@

    here is the mapping:
    @
    mapper->addMapping(ui->comboBox,column);
    MyProxyModel *opm = new MyProxyModel(this);
    opm->setSourceModel(model->relationModel(1));
    ui->comboBox->setModel(opm);
    ui->comboBox->setModelColumn(1);
    model->relationModel(1)->select();@

    another info: the issue exist only if i select an entry that effectively has a surname to concat; if i select someone with an empty surname my selection is conserved (obviously, the empty surname is a strange situation that exist because for testing I haven't inserted full names for everybody)

    1 Reply Last reply
    0
    • P Offline
      P Offline
      p91paul
      wrote on last edited by
      #2

      discovered something: the problem is caused by the delegate.

      @
      mapper->setItemDelegate(new QSqlRelationalDelegate(mapper));@

      when the real data is different from the proxy data, it makes crazy things.
      however, i don't know how to handle this.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        p91paul
        wrote on last edited by
        #3

        well, exploring a bit, I've discovered the problem is inside qt. Since I have no time (and probably not enough skills) to remake the qsqlrelationalmodel class I'm stopping to use it and handle it by hand. when everything would be stable, I will post in the wiki my code snippets, and I hope it would be useful to somebody.
        Paolo

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved