Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, February 2007
how can i interact with the checkbox in QTreeView?(qt4.2.2)


Message 1 in thread

I want to add a checkbox in the treeview, just like the pic in the accessory, I use the QStandarditemModel and set the checkstateRole. 
but there is a question, how can i interact with the checkbox? when i click the checkbox, there is nothing happend :-(

best regards
reimand.zhu

Attachment: Snap1.jpg
Description: image/pjpeg


Message 2 in thread

You have to do a couple of things.

 

First, in the models data, for the role CheckStateRole, return Qt:Checked or Qt::Unchecked depending on if you want it to show checked or not, based on the items state

 

Second, I tend to overload setData, and on the role CheckStateRole, the value (a qvariant) will contain if its checked or not

 

Third, In the setdata, if the check state changes, you will want to emit a datachanged on the index.

 

Scott

 

________________________________

From: llzhu1984 [mailto:llzhu1984@xxxxxxx] 
Sent: Wednesday, February 07, 2007 11:26 PM
To: qt-interest
Subject: how can i interact with the checkbox in QTreeView?(qt4.2.2)

 

I want to add a checkbox in the treeview, just like the pic in the accessory, I use the QStandarditemModel and set the checkstateRole. 
but there is a question, how can i interact with the checkbox? when i click the checkbox, there is nothing happend :-(

best regards
reimand.zhu




________________________________

想加入吗?1.9亿用户正在使用网易邮箱 www.126.com <http://www.126.com/>