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. Qt C++ QComboBox popup two column
Forum Updated to NodeBB v4.3 + New Features

Qt C++ QComboBox popup two column

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 253 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.
  • U Offline
    U Offline
    uart
    wrote on last edited by
    #1

    Hello, I'm designing a combobox that contains 2 column items, and can do filters and shorting based on what is typed in the combobox, the problem is that the combobox doesn't always appear when I write a search.
    ![alt text](qt combo.png image url)

    void Dialog_Sell::getCmbStock(){
    QStandardItemModel *model= new QStandardItemModel(arrStock.size(), 2, this);
    for(int i=0; i<arrStock.size(); i++){
    QStandardItem *kol1 = new QStandardItem( QString("%0").arg(code[i]) );
    QStandardItem *kol2 = new QStandardItem( QString("%0").arg(name[i]) );
    model->setItem(i, 0, kol1);
    model->setItem(i, 1, kol2);
    }

    delegate = new Delegate();
    QTableView* tableView = new QTableView( this );
    QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this);
    
    proxyModel->setSourceModel(model);
    proxyModel->setFilterKeyColumn(-1);
    tableView->setModel( proxyModel);
    tableView->setItemDelegate(delegate);
    tableView->verticalHeader()->setVisible(false);
    tableView->horizontalHeader()->setVisible(false);
    tableView->setColumnWidth ( 0, 60 );
    tableView->setColumnWidth ( 1, 260 );
    tableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    //tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
    tableView->setStyleSheet("background-color: rgb(255, 255, 255);");
    tableView->setAutoScroll(false);
    tableView->setShowGrid(false);
    tableView->setAlternatingRowColors(true);
    tableView->setSortingEnabled(false);
    tableView->setVerticalScrollMode(QTableView::ScrollPerPixel);
    
    
    connect(ui->cmbStock, &QComboBox::editTextChanged, [=]{
        QString query = ui->cmbStock->currentText();
        delegate->setQuery(query);
        //proxyModel->setFilterRegularExpression(query);
        proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
        proxyModel->invalidate();
        //return ;
    });
    
    
    ui->cmbStock->setModel(proxyModel);
    ui->cmbStock->setView( tableView );
    ui->cmbStock->setStyleSheet("QComboBox QAbstractItemView {min-width: 250px;}"
                                "QComboBox { background-color: white; }");
    

    }

    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