Results 1 to 4 of 4

Thread: QTreeView, checkbox problem

  1. #1
    Join Date
    Feb 2009
    Posts
    51
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTreeView, checkbox problem

    Hi,

    Pardon my ignorance and before some one might get into a rant, I did exhaustively search the forum to find answer but still cannot get this work. So please help me out here, experts.

    I am trying to create a tree view with checkbox enclosed using the "Simple Tree Model Example" in the Model/View Programming page. However, I cannot get the checkbox to work. I followed the advice on this forum and make the TreeModel::flags() method return Qt::ItemIsUserCheckable but get stuck at the getData part. Some people suggests that using this method can make the checkboxes check, uncheck. However, I have no clue on how to do that after reading up and down all posts.

    Could you explain on how to do this please?

    Thank you
    Sincerely,

    Wieland J.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTreeView, checkbox problem

    Quote Originally Posted by jwieland View Post
    Pardon my ignorance and before some one might get into a rant, I did exhaustively search the forum to find answer but still cannot get this work. So please help me out here, experts.
    Well, I am not an expert but I try. I have read your view/model stuff, but I'll ignore that. Why? Do you really need your own model or do you just want to have check boxes in your tree view? If so just have a look at QTreeWidget::setItemWidget() and simply pass a normal QCheckBox to your QTreeWidgetItem.

    In case you really need your own view/model thing we will see other solutions...

    Lykurg

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTreeView, checkbox problem

    ...or as in the other post mentioned use QTreeWidget with QTreeWidgetItems where you set:
    Qt Code:
    1. it->setFlags(it->flags() | Qt::ItemIsUserCheckable);
    2. //...
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2009
    Posts
    51
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTreeView, checkbox problem

    Hi Lykurg,

    Thanks for your help. I will give QtreeWidget a try and let you know.

    Much appreciated.
    Sincerely,

    Wieland J.

Similar Threads

  1. Replies: 3
    Last Post: 1st April 2011, 04:58
  2. QTreeView Problem.
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 22nd December 2009, 05:55
  3. QTreeView Problem
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 1
    Last Post: 7th March 2009, 10:32
  4. QTreeView: How to center a checkbox in a cell
    By chezifresh in forum Qt Programming
    Replies: 3
    Last Post: 19th December 2008, 12:11
  5. Selection problem in QTreeView
    By Valheru in forum Qt Programming
    Replies: 3
    Last Post: 7th October 2006, 16:02

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.