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. How in QComboBox with QCheckBox check every CheckBox?
Forum Update on Monday, May 27th 2025

How in QComboBox with QCheckBox check every CheckBox?

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

    I used this code: [https://gist.github.com/mistic100/c3b7f3eabc65309687153fe3e0a9a720](link url)
    to create QComboBox with QCheckBox.
    I created the widget so:
    ```
    ui->SearchChecComboBox->addCheckItem("text0", 0, Qt::Unchecked);
    ui->SearchCheckComboBox->addCheckItem("text1", 1, Qt::Unchecked);
    ui->SearchCheckComboBox->addCheckItem("text2", 2, Qt::Unchecked);
    ui->SearchCheckComboBox->addCheckItem("text3", 3, Qt::Unchecked);

    How to check every CheckBox?
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      "How to check every CheckBox?"
      You mean how to check each if its checked or
      how to create all as checked from start ?

      Anyway, you can do like

       // grab the model
        QStandardItemModel* model = qobject_cast<QStandardItemModel*> ( ui->combobox->model() );
        if (!model) { // check is important or u can/might crash 
          qDebug() << "not QStandardItemModel !";
          return;
        }
      
      -----
      
        // check all if checked
        for (int row = 0; row < model->rowCount(); ++row) {
          if (model->item(row)->checkState() == (Qt::CheckState::Checked)) {
            qDebug() << "checked";
          }
        }
      
        // set all to checked
        for (int row = 0; row < model->rowCount(); ++row) {
          model->item(row)->setCheckState(Qt::CheckState::Checked);
        }
      
      
      1 Reply Last reply
      2

      • Login

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