Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt quick 2 paint method doesn't get called

Tags:

c++

qt

qml

I created a simple Qt quick application and I have an issue drawing with QQuickPaintedItem. I checked in debug mode if the paint gets called, but doesn't. Anyway here's my code:

Source:

ParticleHandler::ParticleHandler(QQuickPaintedItem *parent) : QQuickPaintedItem(parent)
{
    setFlag(QQuickItem::ItemHasContents);
    particle = new Particle();
}
void ParticleHandler::paint(QPainter *painter)
{
    QPen pen = QPen(m_color);
    painter->setPen(pen);
    painter->setRenderHints(QPainter::Antialiasing, true);
    painter->drawEllipse(particle->Position.x,particle->Position.y,particle->Radius/2,particle->Radius/2);
}

Header:

ParticleHandler(QQuickPaintedItem *parent = 0);
void paint(QPainter *painter);
like image 225
Udvardi Péter Avatar asked Sep 01 '25 09:09

Udvardi Péter


1 Answers

Try setting the width and height of your custom item.

import QtQuick 2.0
import Fizika 1.0
Rectangle
{
  width: 360
  height: 360
  Particle
    { 
     width: 100
     height: 100
     radius: 20
     x: 100
     y: 200
     color: "red"
    }
}
like image 58
user2423772 Avatar answered Sep 03 '25 22:09

user2423772