Results 1 to 7 of 7

Thread: Display ItemDelegate Editor always

  1. #1
    Join Date
    Sep 2010
    Posts
    19
    Qt products
    Qt4 Qt/Embedded Qt Jambi

    Default Display ItemDelegate Editor always

    Hi,

    i wrote a little itemdelegate for my tableview:

    Qt Code:
    1. #include "checkboxdelegate.h"
    2.  
    3. #include <QDebug>
    4.  
    5. CheckboxDelegate::CheckboxDelegate(QObject *parent) :
    6. QStyledItemDelegate(parent)
    7. {
    8. }
    9.  
    10. QWidget* CheckboxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option,
    11. const QModelIndex &index) const {
    12.  
    13. QCheckBox *editor = new QCheckBox(parent);
    14. return editor;
    15.  
    16. }
    17.  
    18. void CheckboxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {
    19.  
    20. bool value = index.model()->data(index, Qt::EditRole).toBool();
    21.  
    22. qDebug() << value;
    23.  
    24. QCheckBox *check = static_cast<QCheckBox*>(editor);
    25. check->setChecked(value);
    26.  
    27. }
    28.  
    29. void CheckboxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
    30. const QModelIndex &index) const {
    31.  
    32. QCheckBox *check = static_cast<QCheckBox*>(editor);
    33. model->setData(index, check->isChecked(), Qt::EditRole);
    34.  
    35. qDebug() << "setModelData" << check->isChecked();
    36.  
    37. }
    38.  
    39. void CheckboxDelegate::updateEditorGeometry(QWidget *editor,
    40. const QStyleOptionViewItem &option, const QModelIndex &index) const {
    41.  
    42. editor->setGeometry(option.rect);
    43.  
    44. }
    To copy to clipboard, switch view to plain text mode 

    Everything works fine. If i click on a cell the editor poups up and i'm able to edit the value.

    Now i would like that the editor is always displayed (User sees always the checkbox)

    It this possible?

    Thanks

  2. #2
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display ItemDelegate Editor always

    Try using setModelData in your delegate. This should display your object all of the time.

  3. #3
    Join Date
    Sep 2010
    Posts
    19
    Qt products
    Qt4 Qt/Embedded Qt Jambi

    Default Re: Display ItemDelegate Editor always

    Sry what do you mean?'

  4. #4
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display ItemDelegate Editor always

    Here is an example of doing this for a combo box. You should be able to alter this for using a check box.
    Qt Code:
    1. void ModeDelegate::setModelData(QWidget* editor, QAbstractItemModel* model,
    2. const QModelIndex& index) const
    3. {
    4. QComboBox* comboBox = static_cast<QComboBox*>(editor);
    5. QString value = comboBox->currentText();
    6.  
    7. model->setData(index, value, Qt::EditRole);
    8. }
    9.  
    10. void ModeDelegate::updateEditorGeometry(QWidget* editor,
    11. const QStyleOptionViewItem& option, const QModelIndex &/* index */) const
    12. {
    13. editor->setGeometry(option.rect);
    14. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Sep 2010
    Posts
    19
    Qt products
    Qt4 Qt/Embedded Qt Jambi

    Default Re: Display ItemDelegate Editor always

    Sry but i already have this:

    Qt Code:
    1. void CheckboxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
    2. const QModelIndex &index) const {
    3.  
    4. QCheckBox *check = static_cast<QCheckBox*>(editor);
    5. model->setData(index, check->isChecked(), Qt::EditRole);
    6.  
    7. qDebug() << "setModelData" << check->isChecked();
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 

    The checkbox is only displayed when editing...

  6. #6
    Join Date
    Sep 2010
    Posts
    19
    Qt products
    Qt4 Qt/Embedded Qt Jambi

    Default Re: Display ItemDelegate Editor always

    Can someone help me?
    I would like to display checkboxes always in qtableview

  7. #7
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Display ItemDelegate Editor always

    I guess you need to use a persistent editor?
    These need to be set in the view, not the model I think.

Similar Threads

  1. Replies: 0
    Last Post: 2nd October 2009, 17:57
  2. Can I use a QWidget as a renderer in an ItemDelegate?
    By boblebel in forum Qt Programming
    Replies: 2
    Last Post: 2nd May 2009, 20:03
  3. Replies: 6
    Last Post: 9th January 2008, 15:56
  4. Color table row with ItemDelegate
    By dexjam in forum Newbie
    Replies: 8
    Last Post: 29th June 2006, 12:56
  5. Replies: 5
    Last Post: 16th May 2006, 20:38

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.