Check/Uncheck QCheckBox in QTableView When Item is clicked.



  • I have a QTableView which has 3 Rows and 2 Columns. In my 1st Column I have added the QCheckBox items. If I click the 1st Column's cell. The corresponding QCheckBox has to Check and if i click it again it has to UnCheck. I tried it in below mentioned way,

    @QStandardItem *item = new QStandardItem();
    item->setCheckable(true);
    if(index.data(Qt::CheckStateRole) == Qt::Checked)
    {
    item->setCheckState(Qt::Unchecked);
    modelItem->setItem(index.row(), 0, item);
    }
    else
    {
    item->setCheckState(Qt::Checked);
    modelItem->setItem(index.row(), 0, item);
    }@

    Here i can Check/Uncheck the QCheckBox when the QTableView cell is Clicked. But i cannot directly Check or UnCheck the QCheckBox icon inside the QTableView cell. Please Help how to Check or UnCheck a QCheckBox inside a QTableView's cell.


  • Moderators

    [quote author="Joy Rider" date="1379250644"]
    Here i can Check/Uncheck the QCheckBox when the QTableView cell is Clicked. But i cannot directly Check or UnCheck the QCheckBox icon inside the QTableView cell. [/quote]
    I don't understand this sentence. Please clarify when it is working and when it's not.

    Why you always create a new item. Why don't you just get the item from the index directly and set the checked state?



  • I can able to Check or UnCheck the Table Column when the item (table Column cell) is clicked. But i cannot Check or Uncheck When the QCheckBox Icon is clicked (which is inside the Table Column). i hope you get it.


Log in to reply
 

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