Results 1 to 4 of 4

Thread: Insert QCheckBox into QTableView

  1. #1
    Join Date
    Sep 2006
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Insert QCheckBox into QTableView

    How to insert a QCheckBox into a QTableView?

    The problem is that the checkbox changes when i insert it:

    The third column is a checkbox.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Insert QCheckBox into QTableView

    Simply make sure the flags() method for your model returns Qt::ItemIsUserCheckable and set its Qt::CheckStateRole to something valid.

  3. #3
    Join Date
    Sep 2006
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Insert QCheckBox into QTableView

    Ok. So i subclassed QStandardItemModel, reimplement flags() and make it return
    Qt::ItemIsUserCheckable.

    Then i added a checkbox to model:
    model->setData(index, Qt::Checked, Qt::CheckStateRole);

    How to get some notification when the state of the checkbox is changed?

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Insert QCheckBox into QTableView

    The QAbstractItemModel::dataChanged() signal is emitted when the CheckState is changed. To add your own signals for more specific data changes, you can reimplement the QAbstractItemModel::setData() function and emit custom signals from there..
    J-P Nurmi

Similar Threads

  1. QTableView currentChanged <> selecting header
    By Everall in forum Qt Programming
    Replies: 4
    Last Post: 1st April 2009, 08:24
  2. [Qt4.1] How to insert an image inside a Form?
    By Gonzalez in forum Qt Tools
    Replies: 5
    Last Post: 23rd September 2008, 11:20
  3. how to insert an ' in a database
    By jh in forum General Programming
    Replies: 3
    Last Post: 17th August 2006, 02:47
  4. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42
  5. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 13:49

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.