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. MultiColumnComboBox Model select question
Qt 6.11 is out! See what's new in the release blog

MultiColumnComboBox Model select question

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 575 Views 2 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.
  • D Offline
    D Offline
    deleted28
    wrote on last edited by deleted28
    #1

    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);

    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