Results 1 to 6 of 6

Thread: Implementing TableView with one editable CheckBox

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2010
    Location
    Cincinnati, Ohio, USA
    Posts
    92
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3

    Default Re: Implementing TableView with one editable CheckBox

    I am missing something here. The best I can figure is in the data() method of the model, check to see if the column is the one that should be a check box, if so and if the role is Qt::CheckStateRole, return either Qt::Checked or Qt::Unchecked.

    I did this and it is displaying a checkbox, but it is still to the far left and the original value (zero or one) is also being displayed. When I click on the cell, the number is editable.

    What am I missing?

    Sam

  2. #2
    Join Date
    Jun 2010
    Location
    Cincinnati, Ohio, USA
    Posts
    92
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3

    Question Re: Implementing TableView with one editable CheckBox

    Ok, I found this other thread which enlightened me to enhancing the flag method, too. Since my model extends the QSqlQueryModel, here is what is being returned for the check box column:

    Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsEnabled

    I also tweaked what the data method was returning:
    Qt Code:
    1. if(index.column() == _isInSlideShowIdx)
    2. {
    3. if (role == Qt::CheckStateRole)
    4. return QSqlQueryModel::data(index, Qt::DisplayRole).toBool() ? Qt::Checked : Qt::Unchecked;
    5. else if( role == Qt::DisplayRole)
    6. return QVariant();
    7. }
    To copy to clipboard, switch view to plain text mode 

    But I still have issues:

    1. The check box is always on the left
    2. When I click on the check box cell, it makes the space to the right of the check box an editbox control
    3. When I added a delegate to create a check box editor, I had to still double click on the space to the right to make the editor active, and the editor is offset to the left by a pixel or two.


    Any thoughts on how to fix this?

  3. #3
    Join Date
    Jun 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Implementing TableView with one editable CheckBox

    Hi scarleton,

    perhaps this will help
    Qt Code:
    1. ui->tableWidget->setEditTriggers(QAbstractItemView::SelectedClicked);
    To copy to clipboard, switch view to plain text mode 

  4. #4

    Default Re: Implementing TableView with one editable CheckBox

    Hello,

    Try void QAbstractItemView:penPersistentEditor ( const QModelIndex & index ) !

    I think this is what you want !

    Kaku

Similar Threads

  1. Need help with checkbox in tableview
    By vieraci in forum Qt Programming
    Replies: 5
    Last Post: 21st June 2009, 14:13
  2. implementing 'scrollview'
    By rishiraj in forum Newbie
    Replies: 1
    Last Post: 18th December 2008, 13:23
  3. implementing drawForeGround
    By Wirloff in forum Newbie
    Replies: 9
    Last Post: 11th April 2007, 17:03
  4. Implementing IME using QT
    By pmohod in forum Qt Programming
    Replies: 0
    Last Post: 16th February 2007, 13:22
  5. Implementing gif images in QT 3.3.2
    By vvbkumar in forum Qt Programming
    Replies: 3
    Last Post: 21st July 2006, 18:16

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
  •  
Qt is a trademark of The Qt Company.