multiple columns combobox



  • why does this code not work for qt5.9 ? no item be selectted. i want to make 24 items to 2 columns, each item is clickable

    the code comes from forum

    ui->setupUi(this);
    
        QStandardItemModel model(5, 3);
        for(int i = 0; i < model.rowCount(); i++)
        {
            QStandardItem *col0 = new QStandardItem(QString("foobar%1").arg(i));
            QStandardItem *col1 = new QStandardItem(QString("foo%1").arg(i));
            QStandardItem *col2 = new QStandardItem(QString("bar%1").arg(i));
    
            model.setItem(i, 0, col0);
            model.setItem(i, 1, col1);
            model.setItem(i, 2, col2);
        }
    
        ui->comboBox->setModel(&model);
        QTreeView *treeView = new QTreeView(ui->comboBox);
        ui->comboBox->setView(treeView);
    
        treeView->setColumnHidden(0, true);
        treeView->setSelectionBehavior(QAbstractItemView::SelectRows);
        treeView->setAllColumnsShowFocus(true);
        treeView->setRootIsDecorated(false);
        treeView->header()->hide();
    

  • Qt Champions 2017

    Hi
    The "treeView->setSelectionBehavior(QAbstractItemView::SelectRows);"
    tell it to select whole rows, not cells.
    Try with
    QAbstractItemView::SelectItems



  • @mrjj not work, not the reason


  • Qt Champions 2017

    @Davidcheng

    well code worked for me so you must provide more details to "not work"
    in order to help you.



  • Shooting in the dark here but what about: http://doc.qt.io/qt-5/qcombobox.html#modelColumn-prop

    The default is 0 and you hide that column



  • @mrjj i got this 0_1513602980485_Screenshot from 2017-12-18 21-15-47.png



  • @VRonin comment //treeView->setColumnHidden(0, true); does not work.
    could you show the code?



  • @Davidcheng said in multiple columns combobox:

    could you show the code?

    treeView->setModelColumn(1);


Log in to reply
 

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