Error calling base class's 'paint' method.

  • I'm subclassing QAbstractItemDelegate to display certain data differently, but for text data, I simply want to print it normally, so I'm trying to call the base class's paint method:

    void Prop_Delegate::paint(QPainter *painter, const QStyleOptionViewItem &style, const QModelIndex &idx) const {
    QAbstractItemDelegate::paint(painter, style, idx);

    However, this gives the error: Undefined symbols for architecture x86_64. Can someone please tell me what is wrong? I included QAbstractItemDelegate in the header, and calling QAbstractItemDelegate::parent() doesn't raise any error. Here is the complete source:

    #ifndef PROP_DELEGATE_H
    #define PROP_DELEGATE_H

    #include <QAbstractItemDelegate>

    class Prop_Delegate : public QAbstractItemDelegate {

    Prop_Delegate(QObject *p = 0) : QAbstractItemDelegate(p) {};

    // necessary overloaded methods.                                                                                                        
    void paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const;                                                        
    QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const;                                                                



    #include "prop_delegate.h"
    #include "tile.h"

    #include <QPainter>
    #include <QSize>

    void Prop_Delegate::paint(QPainter *painter, const QStyleOptionViewItem &style, const QModelIndex &idx) const {
    switch (idx.column()){
    case 0:
    if (idx.model()->data(idx, Qt::DisplayRole).toBool())
    painter->fillRect(style.rect, style.palette.highlight());
    case 1:
    QAbstractItemDelegate::paint(painter, style, idx);

    QSize Prop_Delegate::sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const {
    return QSize(21, 100);


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Basic checks:

    Which version of Qt are you using ? If Qt 5, did you add

    @QT += widgets@

    to your pro file ?

    If so, are you building in 32bit mode and linking to a 64bit Qt ?

  • Sorry, yes I'm using Qt 5.2 (the error was also there in 5.1). I did add "QT += widgets" in my pro file. I'm not sure about what mode I'm building in or linking in. I just type 'make' in the terminal. So far, I haven't gotten any problems. Is there any way to force it to build and compile in the same mode? Thanks.

  • Moderators

    The word abstract in QAbstractItemDelegate is not random :) This is an abstract class and paint() is a pure virtual method so you can't call it.

  • Lifetime Qt Champion

    Shame on me… Too used to QStyledItemDelegate… Which you should use by the way

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.