Results 1 to 3 of 3

Thread: checkbox on QListView

  1. #1
    Join Date
    Jul 2010
    Posts
    23
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default checkbox on QListView

    Is it possible to turn on or use checkbox as one of my listItem? For example,
    I have a list:
    item1
    item2
    item3
    ...
    I want to have the ability to set or unset the checkbox for all items (checkbox and text of the item on the column). I use the QStringListModel to handle the view now. How can I add this feature to my model to show up on my QListView? Thanks.

  2. #2
    Join Date
    Apr 2011
    Location
    Russia
    Posts
    85
    Thanks
    2
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: checkbox on QListView

    Qt Code:
    1. item->setData( Qt::DisplayRole, "text" );
    2. item->setData( Qt::CheckStateRole, Qt::Checked );
    3. listWidget->addItem( item );
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. Item->setCheckable( true );
    2. Item->setCheckState( Qt::Checked );
    3. model->setItem( 0, Item );
    4. listView->setModel( model );
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2013
    Posts
    6
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Windows

    Default Re: checkbox on QListView

    @Jonny174: Thanks for your useful code! It is really helpful. But how can I know what the checkbox is checked after I added checkbox for all items in QListView?

    Thanks!

    Quote Originally Posted by Jonny174 View Post
    Qt Code:
    1. item->setData( Qt::DisplayRole, "text" );
    2. item->setData( Qt::CheckStateRole, Qt::Checked );
    3. listWidget->addItem( item );
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. Item->setCheckable( true );
    2. Item->setCheckState( Qt::Checked );
    3. model->setItem( 0, Item );
    4. listView->setModel( model );
    To copy to clipboard, switch view to plain text mode 
    Last edited by LeeMinh; 18th July 2013 at 13:08.

Similar Threads

  1. Replies: 4
    Last Post: 1st June 2011, 15:54
  2. checkbox
    By fluefiske in forum Newbie
    Replies: 3
    Last Post: 5th October 2010, 23:41
  3. QSpinBox with checkbox
    By :db:sStrong in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2007, 14:22
  4. checkbox
    By nErnie in forum Qt Programming
    Replies: 1
    Last Post: 25th September 2006, 22:59
  5. checkBox
    By mickey in forum Qt Programming
    Replies: 8
    Last Post: 2nd April 2006, 00:05

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.