[SOLVED] QPaintedItem : Update don't call paint()



  • Hi!
    I'm trying to do something like this tuto : http://qt-project.org/doc/qt-5/qtquick-customitems-painteditem-example.html
    But with an explicit use of update function in c++. update() never call paint()...

    Part of code :
    C++ :

    • header
      @class KLeapFinger : public QQuickPaintedItem {

      Q_OBJECT

    public:
    KLeapFinger(QQuickItem * parent = 0);
    void paint(QPainter * painter);

    public slots:
    void drawPointables(QVector<QPoint> pointList);

    private:
    QVector<QPoint> m_pointList;

    };@

    • Source
      @////////////////////////////////////////////////////////////////
      //////////////////// CLASS KLEAPFINGER /////////////////////////
      ////////////////////////////////////////////////////////////////
      KLeapFinger::KLeapFinger(QQuickItem *parent) : QQuickPaintedItem(parent)
      {
      this->setFlag(QQuickItem::ItemHasContents, true); // No visible change with or without
      }

    ////////////////////////////////////////////////////////////////
    void KLeapFinger::drawPointables(QVector<QPoint> pointList)
    {
    qDebug() << "KLeapFinger::drawPointables"; // well display
    m_pointList = pointList;

    update();
    qDebug() << contentsBoundingRect(); // QRectF(0,0 0x0)
    qDebug() << contentsSize(); // QSize(-1, -1)
    

    }

    ////////////////////////////////////////////////////////////////
    void KLeapFinger::paint(QPainter *painter)
    {
    qDebug() << "paint !!" << m_pointList.first(); // Never display (except one time at the start, or when resize the windows)
    QVector<QPoint>::iterator it;
    for(it = m_pointList.begin() ; it < m_pointList.end() ; it++)
    {
    painter->setPen(Qt::white);
    painter->drawEllipse(*it, 25, 25);
    qDebug() << *it;
    }
    }

    ////////////////////////////////////////////////////////////////
    /////////////// END OF CLASS KLEAPFINGER ///////////////////////
    ////////////////////////////////////////////////////////////////@

    QML :
    @ KLeapFinger {
    id: fingerPainter
    anchors.fill: parent
    }@

    Thank a lot !


  • Moderators

    Hi,

    Welcome. Can you show where do you call drawPointables() ?



  • Hi, thank!

    I'm using a signal, which is emit regulary (maybe 10 time/sec)

    @m_kLeapFinger = new KLeapFinger();
    connect(this, SIGNAL(drawPointables(QVector<QPoint>)),m_kLeapFinger, SLOT(drawPointables(QVector<QPoint>)));
    @
    @emit drawPointables(pointList);@


  • Moderators

    Well i see something fishy here. Your SLOT is same as that of SIGNAL. Is that a typo ? Have you declared the SIGNAL in header ? Since i don't see it in the code pasted above.



  • To be sure I change the name...
    Yes the signal is well declared, I don't think the problem is here. As I wrote in comment in my code, qDebug() is well display in the slot, and well display in the paint ONLY when I resize the windows, never when I call update()..


  • Moderators

    Ok, Can you show how have you registered KLeapFinger component ? in main.cpp ?



  • Main:
    @qmlRegisterType<KLeapFinger>("KLeap", 1, 0, "KLeapFinger");@

    QML:
    @import KLeap 1.0@


  • Moderators

    IMO, the problem here is the KLeapFinger which you are using in the QML and the one which you have created using new are totally different. And you have connected signals to the KLeapFinger that was created using new and not the KLeapFinger used in QML.
    You can declare a timer in the KLeapFinger class itself or use a timer in the QML and call the function which then calls update.



  • That's it ! Thank you !
    (I made the connection between c++ object in the QML)


  • Moderators

    Ok.
    You're Welcome. Happy Coding :)


Log in to reply
 

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