Checkable box with QAbstractTableModel implementation

  • I need to add a checkbox to my TableView through my model. I've already added the

    if ( role == Qt::CheckStateRole && index.column() == CHECKBOX_COL )
        retval = Qt::Unchecked;

    I've also attempted the setDataFunction. However, I cannot check the checkbox. I was wondering if anyone had an example where you can check rows of data in a TableView and where I'm able to capture the check or uncheck via a signal. I'll also be implementing check all and uncheck all functionality via buttons; however, would like to get the check buttons working properly first.


  • Moderators

    did you forget to add the Qt::ItemIsUserCheckable in the model's flag() implementation? (For the relevant model index)

  • @HunterMetcalfe said in Checkable box with QAbstractTableModel implementation:

    where I'm able to capture the check or uncheck via a signal

    If you are implementing your own model add the optional const QVector<int> &roles as last argument to the dataChanged() signal and in the slot check that roles.contains(Qt::CheckStateRole)



    const int numRows = model->rowCount(idx);
    for(int i=0;i<numRows ;++i)

    with emit checkChanged(idx);

  • Thanks for the replies! I will try exactly this. I apologize for the delay. Many other projects to be completed.

Log in to reply

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