Results 1 to 2 of 2

Thread: Why does the table cell containing checkbox becomes solid when it is clicked?

  1. #1

    Default Why does the table cell containing checkbox becomes solid when it is clicked?

    I have a table view which uses a customized model. In the table view, there are many check boxes. Clicking any of the check boxes will make the parent cell becomes solid. The check state is saved though. Clicking some other cell will make it back to normal.

    solid cell..PNGback to normal..PNG

    It seems the issue is new in Qt 4.5 and 4.6, it was good in version 4.3.

    The source code of the example is attached. (Why cannot I attach a zip file?) The application is built using Qt 4.6.2, on Windows platform.

    Cannot upload tablemodel.h either. So I copy code directly.
    Qt Code:
    1. #ifndef TABLEMODEL_H
    2. #define TABLEMODEL_H
    3.  
    4. #include <QtCore/QAbstractTableModel>
    5.  
    6. static const int ROWS = 2;
    7. static const int COLS = 2;
    8.  
    9. class TableModel : public QAbstractTableModel
    10. {
    11. Q_OBJECT
    12.  
    13. public:
    14. TableModel(QObject *parent = 0)
    15. {
    16. }
    17.  
    18. int rowCount(const QModelIndex &parent = QModelIndex()) const { return ROWS; }
    19. virtual int columnCount(const QModelIndex &parent = QModelIndex()) const { return COLS; }
    20.  
    21. virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const
    22. {
    23. switch(role)
    24. {
    25. case Qt::CheckStateRole:
    26. return enabled_[index.row()][index.column()] ? Qt::Checked : Qt::Unchecked;
    27.  
    28. default:
    29. break;
    30. }
    31.  
    32. return QVariant();
    33. }
    34.  
    35. virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole)
    36. {
    37. switch(role)
    38. {
    39. case Qt::CheckStateRole:
    40. if (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked)
    41. enabled_[index.row()][index.column()] = true;
    42. else
    43. enabled_[index.row()][index.column()] = false;
    44.  
    45. return true;
    46.  
    47. default:
    48. break;
    49. }
    50.  
    51. return QAbstractTableModel::setData(index, value, role);
    52. }
    53.  
    54. virtual Qt::ItemFlags flags(const QModelIndex &index) const
    55. {
    56. return QAbstractTableModel::flags(index) | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
    57. }
    58.  
    59. private:
    60. bool enabled_[ROWS][COLS];
    61. };
    62.  
    63. #endif // TABLEMODEL_H
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files
    Last edited by lornazh; 8th April 2010 at 06:08. Reason: updated contents

  2. #2
    Join Date
    Aug 2008
    Location
    Texas, USA
    Posts
    44
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why does the table cell containing checkbox becomes solid when it is clicked?

    I'm using 4.6.0 and it worked good for me.

Similar Threads

  1. QTreeView cell as table
    By ^NyAw^ in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2009, 10:45
  2. QTreeView: How to center a checkbox in a cell
    By chezifresh in forum Qt Programming
    Replies: 3
    Last Post: 19th December 2008, 13:11
  3. Making Table cell as a combobox?
    By kaushal_gaurav in forum Qt Programming
    Replies: 9
    Last Post: 1st August 2008, 13:04
  4. How can I get the value of the clicked cell in a QListView
    By murari2002 in forum Qt Programming
    Replies: 2
    Last Post: 27th September 2007, 18:18
  5. Table cell merge/join
    By larry104 in forum Qt Programming
    Replies: 6
    Last Post: 16th June 2006, 23:35

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.