MultiColumnComboBox Model select question



  • Hello,
    following code creates a 2column QComboBox.
    void MainWindow::populateCbToFire() {
    // multicolumn fill cb_toFire

    QMap<QString, QString>cmdMap;
    cmdMap.insert("init__0","AA 0D 00 FF 0A 00 00 00 FF FF FF FF 00 00");
    cmdMap.insert("init__1","AA 15 00 FE 0A 00 00 00 FF FF FF FF 00 00 0A 00 00 00 10 77 00 82");
    cmdMap.insert("init__2","AA 11 00 01 0A 00 00 00 FF FF FF FF 00 00 00 01 00 00");
    cmdMap.insert("init__3","AA 25 00 01 0A 00 00 00 FF FF FF FF 00 00 00 02 00 0D 10 00 21 A8 68 07 2F 10 0A 01 EF 19 F4 53 47 00");
    cmdMap.insert("init__4","AA 11 00 01 0A 00 00 00 FF FF FF FF 00 00 00 02 00 0E");
    cmdMap.insert("init__5","AA 25 00 01 0A 00 00 00 FF FF FF FF 00 00 00 02 00 0D 06 00 10 00 21 A8 00 00 00 00 E0 93 04 00 F4 53 47 00");
    cmdMap.insert("init__6","AA 13 00 01 0A 00 00 00 00 00 00 00 00 00 00 02 00 01 00 00 ");
    
    QStandardItemModel *model = new QStandardItemModel(cmdMap.count(), 2, this );
    QMap<QString, QString>::const_iterator it = cmdMap.constBegin();
    int cnt = 0;
    while (it != cmdMap.end()) {
        QStandardItem* col0 = new QStandardItem(QString("%1").arg(it.key()));
        QStandardItem* col1 = new QStandardItem(QString("%1").arg(it.value()));
        model->setItem(cnt, 0, col0);
        model->setItem(cnt, 1, col1);
        it++; cnt++;
    }
    
    QTableView* tableView = new QTableView(this);
    tableView->setModel(model);
    
    tableView->verticalHeader()->setVisible(false);
    tableView->horizontalHeader()->setVisible(false);
    
    tableView->resizeColumnsToContents();
    tableView->resizeRowsToContents();
    
    tableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
    
    tableView->setAutoScroll(false);
    
    ui->cb_toFire->setModel(model);
    ui->cb_toFire->setView(tableView);
    

    }

    The "popdown" of the ComboBox shows both columns.
    When i select a row with mouse, the 1st column only is shown on Top of box.
    Here i want the second column to be shown, so i also get 2nd column when
    calling "ui->cb_toFire->currentText()" .
    How to do this ?

    just setting modelcolumn to 1 seems to do the job,
    but in the drop-down area of the combobox the first column is not visible now.
    ui->cb_toFire->setModelColumn(1);


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.