<?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[Qt scrolling a image within QLabel]]></title><description><![CDATA[<p dir="auto">Manage to create Bullet and every 50msec, bullet pixmap is moved.<br />
But i want to create within QLabel.  Please assist.</p>
<p dir="auto">@ --Bullet.c--</p>
<p dir="auto">Bullet::Bullet(QGraphicsItem *parent): QObject(), QGraphicsPixmapItem(parent){<br />
// draw graphics<br />
setPixmap(QPixmap(":/images/bullet.png"));</p>
<pre><code>// make a timer to move bullet every 50ms
QTimer * timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(move()));

// start the timer every 50 ms
timer-&gt;start(50);
</code></pre>
<p dir="auto">}</p>
<p dir="auto">void Bullet::move(){<br />
// move the bullet forward<br />
setPos(x()-10,y());<br />
// if the bullet is off the screen, destroy it<br />
if (pos().x() &lt; 0){<br />
scene()-&gt;removeItem(this);<br />
delete this;<br />
}<br />
}</p>
<p dir="auto">//---Bullet.h<br />
#ifndef BULLET_H<br />
#define BULLET_H</p>
<p dir="auto">#include &lt;QGraphicsPixmapItem&gt;<br />
#include &lt;QGraphicsItem&gt;<br />
#include &lt;QObject&gt;</p>
<p dir="auto">class Bullet: public QObject,public QGraphicsPixmapItem {<br />
Q_OBJECT<br />
public:<br />
Bullet(QGraphicsItem * parent=0);<br />
public slots:<br />
void move();<br />
};</p>
<p dir="auto">#endif // BULLET_H</p>
<p dir="auto">@</p>
<p dir="auto">@ main.cpp</p>
<pre><code>     // create the scene
     scene = new QGraphicsScene();
     scene-&gt;setSceneRect(0,0,800,600); 
     ui-&gt;graphicsView-&gt;setScene(scene);

    // Label created
    imageLabel = new QLabel;
    imageLabel -&gt;setBackgroundRole(QPalette::Base);

    //Bullet created
    Bullet * bullet = new Bullet();
    bullet-&gt;setPos(x(),y());
    scene()-&gt;addItem(bullet);
</code></pre>
<p dir="auto">@</p>
]]></description><link>https://forum.qt.io/topic/51680/qt-scrolling-a-image-within-qlabel</link><generator>RSS for Node</generator><lastBuildDate>Sat, 08 Aug 2026 18:41:34 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/51680.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 26 Feb 2015 09:30:32 GMT</pubDate><ttl>60</ttl></channel></rss>