<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Help with QPainter arc math]]></title><description><![CDATA[<p dir="auto">I'm trying to make a ball-character that shows scrolling arcs when it moves to create the illusion of a 3d ball. The ball is drawn as an 80x80 pixmap with this code, (<code>f</code> is a global variable that refers to the frame count):</p>
<pre><code>QPixmap *Character::getPixmap(){
	QPixmap *pixmap = new QPixmap(80, 80);
	pixmap-&gt;fill(Qt::transparent);
	
	QPainter painter(pixmap);
	painter.setRenderHint(QPainter::Antialiasing);
	painter.setRenderHint(QPainter::SmoothPixmapTransform);
	
	painter.setBrush(QBrush(QColor(255, 255, 255));
	painter.drawEllipse(QRectF(0, 0, 79, 79));
	
	for(int i = (f % 10); i &lt;= 80; i += 10){
		if(i&lt;50) painter.drawArc(0, i, 79, 80-i*1.5, 0, 180*16);
		else painter.drawArc(0, 50-(i-50), 79, (i-55)*2, 180*16, 180*16);
	}
	
	painter.end();
	return pixmap;
}
</code></pre>
<p dir="auto">The main loop draws a green background and then the character at a rate of about 30fps, and the result looks like this: <a href="https://youtu.be/anAy4URYLxo" target="_blank" rel="noopener noreferrer nofollow ugc">&lt;YouTube link&gt;</a></p>
<p dir="auto">Can anyone help me adjust the arc animation? (It doesn't really matter how many arcs there are, although a version that uses a macro to determine the arc number would be very appreciated!)</p>
]]></description><link>https://forum.qt.io/topic/138097/help-with-qpainter-arc-math</link><generator>RSS for Node</generator><lastBuildDate>Mon, 09 Nov 2026 01:43:03 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/138097.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 22 Jul 2022 13:34:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Help with QPainter arc math on Fri, 22 Jul 2022 15:08:50 GMT]]></title><description><![CDATA[<p dir="auto">Sorry, I should have provided some code to test it.</p>
<pre><code>#include &lt;QtWidgets&gt;

unsigned long f = 0;

class Character : public QWidget {
public:
	Character();
	~Character();
	
	QPixmap *getPixmap();
protected:
	void paintEvent(QPaintEvent *e);
};

Character::Character() : QWidget(){}
Character::~Character(){}

void Character::paintEvent(QPaintEvent *event){
	Q_UNUSED(event);

	QPainter painter(this);
	painter.setRenderHint(QPainter::Antialiasing);
	painter.setRenderHint(QPainter::SmoothPixmapTransform);
	
	painter.setBrush(QBrush(QColor(255, 255, 255)));
	painter.drawEllipse(QRectF(0, 0, 79, 79));
	
	for(int i = (f % 10); i &lt;= 80; i += 10){
		if(i&lt;50) painter.drawArc(0, i, 79, 80-i*1.5, 0, 180*16);
		else painter.drawArc(0, 50-(i-50), 79, (i-55)*2, 180*16, 180*16);
	}
	
	painter.end();
	f++;
}

int main(int argc, char *argv[]){
	QApplication app(argc, argv);
	Character *c = new Character();
	
	QTimer t;
	QObject::connect(&amp;t, &amp;QTimer::timeout, c, static_cast&lt;void(QWidget::*)()&gt;(&amp;QWidget::update));
	t.start(30);
	
	c-&gt;show();
	return app.exec();
}
</code></pre>
]]></description><link>https://forum.qt.io/post/722316</link><guid isPermaLink="true">https://forum.qt.io/post/722316</guid><dc:creator><![CDATA[sammonius]]></dc:creator><pubDate>Fri, 22 Jul 2022 15:08:50 GMT</pubDate></item></channel></rss>