Capture checkbox check/uncheck via delegates paint?



  • I've been unable to get this to work. I have a TreeView with a custom model and in my TreeView's delegate I am trying to capture if a checkbox was checked or unchecked so I added the following to the pain() method.

    void MyTreeViewDelegate::paint(QPainter *painter,
    const QStyleOptionViewItem &option, const QModelIndex &index) const
    {
        // ...
    
        if (option.state & QStyle::State_Off) {
            std::cout << "Checkbox Unchecked!" << std::endl;
        }
    }
    

    But this never gets called. Thoughts?


  • Lifetime Qt Champion

    Hi
    bool isChecked = index.data(Qt::CheckStateRole).toBool();
    works for me with treeview and standarditem model.


Log in to reply
 

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