Results 1 to 4 of 4

Thread: QCheckBox in QTreeWidget

  1. #1
    Join Date
    Dec 2009
    Posts
    18
    Thanks
    1

    Default QCheckBox in QTreeWidget

    Hi there,
    I'm add a QCheckBoxin my QTreeWidget like these, but, How to set the widget to be center of the column rect?
    Qt Code:
    1. treeWidget->setItemWidget(subItem, 2, chkItem);
    2. subItem->setTextAlignment(2, Qt::AlignHCenter);
    3. Qt::CheckState chkState = (bNeedSync.toInt() == 1) ? Qt::Checked : Qt::Unchecked;
    4. chkItem->setCheckState(chkState);
    To copy to clipboard, switch view to plain text mode 
    I digged the code and this forum and no without any tip information. Thanks.
    image.PNG

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QCheckBox in QTreeWidget

    You will need to use your own delegate. Look for QItemDelegate and QStyledItemDelegate. In that you will need to set the position for check and draw.

  3. #3
    Join Date
    Dec 2009
    Posts
    18
    Thanks
    1

    Default Re: QCheckBox in QTreeWidget

    Quote Originally Posted by aamer4yu View Post
    You will need to use your own delegate. Look for QItemDelegate and QStyledItemDelegate. In that you will need to set the position for check and draw.
    Accturally, I don't know how to set the rect of the checkbox item. I use QTreeWidget with QStyledItemDelegate instead of QTreeView, you know, in Model-View, I can control every thing I need.
    But in QTreeWidget, It seems not easy for handle this.

    I wrote an example in my QStyleItemDelegate subclass,
    Qt Code:
    1. void CMTreeDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
    2. {
    3. Q_ASSERT(index.isValid());
    4.  
    5. QStyleOptionViewItem opt = option;
    6. // draw the check box
    7. if ( index.column() == 2 )
    8. {
    9. return;
    10. }
    11.  
    12. QStyledItemDelegate::paint(painter, opt, index);
    13. }
    To copy to clipboard, switch view to plain text mode 
    The check box still showen in the column. obviousely, the delegate can not control the rect of the Checkbox which created with
    Qt Code:
    1. treeWidget->setItemWidget(subItem, 2, chkItem);
    2. subItem->setTextAlignment(2, Qt::AlignHCenter);
    3. Qt::CheckState chkState = (bNeedSync.toInt() == 1) ? Qt::Checked : Qt::Unchecked;
    4. chkItem->setCheckState(chkState);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QCheckBox in QTreeWidget

    Am not sure how to do with QStyledItemDelegate. But with QItemDelegate you need to set the rect in option.,, and then call drawCheck.
    Look into Qt source code,,, you will get an idea of what calls are done to do the drawing

Similar Threads

  1. QTableWidget with QCheckBox
    By reinki0013 in forum Qt Programming
    Replies: 5
    Last Post: 8th December 2009, 08:34
  2. QTreeWidget and QCheckBox
    By mydear1986 in forum Qt Programming
    Replies: 1
    Last Post: 12th April 2009, 09:33
  3. QCheckBox value
    By Koas in forum Qt Programming
    Replies: 2
    Last Post: 19th January 2009, 13:33
  4. Replies: 2
    Last Post: 17th March 2008, 12:53
  5. QCheckbox
    By sonuani in forum Qt Programming
    Replies: 1
    Last Post: 19th February 2008, 13:12

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.