[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 !
-
-
Hi,
Welcome. Can you show where do you call drawPointables() ?
-
-
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().. -
Ok, Can you show how have you registered KLeapFinger component ? in main.cpp ?
-
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. -
Ok.
You're Welcome. Happy Coding :)