Results 1 to 4 of 4

Thread: createEditor() is not called in custom delegate

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

    Default createEditor() is not called in custom delegate

    Hi,

    i nearly searched all the web for this problem. My last chance is to post my problem here.

    I need a tableWidget that contains multiple strings and checkboxes in one row. These checkboxes should change their value be clicking once.
    So i created a delegate to customize a tableWidget. It almost does the things i needed, but when i change the triggers for editing the tableWidget to "SelectedClick" only, the delegate functions "createEditor","setEditor" and "setModelData" would not be called. The are called, if i double click the checkbox field, to enter editor mode, but that's not what i want.

    So, does anyone have an hint?
    Thanks.

    For your information: Qt 4.6.3 on ubuntu and that little attached project is only a test to demonstrate my problem...
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: createEditor() is not called in custom delegate

    Try this:

    Add the following to tab::tab (i.e. the constructor):
    Qt Code:
    1. ui->tableWidget->setItemDelegateForColumn(2,new myTableDelegate());
    2. ui->tableWidget->setItemDelegateForColumn(3,new myTableDelegate());
    3. connect(ui->tableWidget,SIGNAL(cellClicked(int,int)),this,SLOT(cell_clicked(int, int)));
    To copy to clipboard, switch view to plain text mode 
    Remove these lines from tab:: on_bt_show_clicked():
    Qt Code:
    1. //ui->tableWidget->setItemDelegate(new myTableDelegate());
    2. // ui->tableWidget->setEditTriggers(QAbstractItemView::SelectedClicked);
    3. //ui->tableWidget->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked);
    To copy to clipboard, switch view to plain text mode 
    And create a custom slot:
    Qt Code:
    1. void tab::cell_clicked(int row, int col) {
    2. if(ui->tableWidget->item(row, col)->checkState() == Qt::Checked) ui->tableWidget->item(row, col)->setCheckState(Qt::Unchecked);
    3. else ui->tableWidget->item(row, col)->setCheckState(Qt::Checked);
    4. }
    To copy to clipboard, switch view to plain text mode 

    Be sure to declare the slot in "tab.h"

    HTH

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

    Default Re: createEditor() is not called in custom delegate

    ok, your hint makes it worse than before...
    But now i use the "cellClicked(int,int)" signal from tableWidget and the custom tabledelgate, i wrote, is almost unnecessary...

    Thanks a lot...

  4. #4
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: createEditor() is not called in custom delegate

    Quote Originally Posted by landstreicher View Post
    ok, your hint makes it worse than before...
    How so?
    But now i use the "cellClicked(int,int)" signal from tableWidget and the custom tabledelgate, i wrote, is almost unnecessary...
    Correct. All you need is the paint method to draw checkboxes. Attached is a simple example.
    Attached Files Attached Files
    Last edited by norobro; 22nd July 2010 at 04:20. Reason: gzip file corrupted on upload

Similar Threads

  1. Error in custom delegate
    By philacorns in forum Newbie
    Replies: 4
    Last Post: 21st April 2010, 05:41
  2. Replies: 3
    Last Post: 5th April 2010, 21:20
  3. Custom Model? Custom View? Custom Delegate?
    By Doug Broadwell in forum Newbie
    Replies: 4
    Last Post: 11th February 2010, 20:23
  4. Replies: 0
    Last Post: 1st February 2010, 11:00
  5. Question about custom view (or custom delegate)
    By skuda in forum Qt Programming
    Replies: 1
    Last Post: 21st September 2009, 20:06

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.