Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Error calling base class's 'paint' method.
Forum Update on Monday, May 27th 2025

Error calling base class's 'paint' method.

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    litearc
    wrote on last edited by
    #1

    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:

    prop_delegate.h
    @
    #ifndef PROP_DELEGATE_H
    #define PROP_DELEGATE_H

    #include <QAbstractItemDelegate>

    class Prop_Delegate : public QAbstractItemDelegate {
    Q_OBJECT

    public:
    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;                                                                
    

    };

    #endif
    @

    prop_delegate.cpp
    @
    #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:
    painter->save();
    if (idx.model()->data(idx, Qt::DisplayRole).toBool())
    painter->fillRect(style.rect, style.palette.highlight());
    painter->restore();
    break;
    case 1:
    QAbstractItemDelegate::paint(painter, style, idx);
    break;
    }
    }

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

    Thanks!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • L Offline
        L Offline
        litearc
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

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

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved