Results 1 to 4 of 4

Thread: QTableView doesn't use delegate

  1. #1
    Join Date
    Dec 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X

    Default QTableView doesn't use delegate

    I have a QTableView, a QSqlTableModel, and an QItemDelegate subclass. I create my model, and set that on the table view. I create my delegate, and call tableView->setItemDelegate(new MyDelegate());.

    When my window display, the table does display the data from the SQL table. However, not a single method in my delegate is called. I implement
    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const;
    void setEditorData(QWidget *editor, const QModelIndex &index) const;
    void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;

    and have a log statement as the first line in each method. None gets hit.

    Is there something about the combination of thee three classes that make them incompatible? Am I missing something?

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTableView doesn't use delegate

    Please use the CODE tags next time since your code is not really readable.
    And then you just reimplemented functions which came in action if you edit the data of a model. So while debuging, do you alter the data of your model?

  3. #3
    Join Date
    Sep 2008
    Posts
    54
    Thanks
    3
    Thanked 10 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default Re: QTableView doesn't use delegate

    Hello,

    I had the same kind of problem with my CustomModel and CustomDelegate. Problem was that I did not implemented the methods in the model to make it editable:

    Qt Code:
    1. // For making the items editable
    2. Qt::ItemFlags flags( const QModelIndex & index ) const;
    3. bool setData (const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
    To copy to clipboard, switch view to plain text mode 

    See QT documentation -> Model Subclassing Reference ->Editable items

    Hope this helps.

    regards,

    Marcel

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView doesn't use delegate

    Did you use QAbstractItemView::setEditTriggers ??
    Normally the functions you mentioned in the first post will be called when editor is to be called.
    An editor will be called if the item is editable and the triggers have been activated.

Similar Threads

  1. Replies: 15
    Last Post: 11th December 2012, 21:10
  2. Replies: 5
    Last Post: 25th May 2011, 11:10
  3. Replies: 1
    Last Post: 15th April 2009, 10:00
  4. QTableView in ui with model/delegate
    By tpf80 in forum Qt Programming
    Replies: 7
    Last Post: 7th November 2008, 00:00
  5. QTableView Delegate Usage
    By rajeshs in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2008, 08:03

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.