[Qt-interest] How to move a pixmap around a scene if I've overridden the paint() method?
Topi Hukkanen
topi.hukkanen at gmail.com
Tue Nov 3 20:21:09 CET 2009
Hi All,
I'm still having trouble with this.
I've tried everything I can think of, but I still can't get the QPixmap to
change location in the scene.
I've had a problem like this before, and I've never been able to solve it.
I don't know if it's a bug in 4.4.3 or something else...
Any ideas?
-Topi
On Sat, Oct 31, 2009 at 12:01 PM, Topi Hukkanen <topi.hukkanen at gmail.com>wrote:
> Hi,
>
> I have been trying to paint a QPixmap (Finger) on screen and move it along
> the x-axis by following the location of the mouse cursor.
>
> The movements were working when I derived my Finger class from
> QGraphicsProxyWidget and put inside that was a QPixmap inside a QLabel...
> but I was having trouble with large pixmaps over 1000 pixels wide (only ~1/2
> of the pixmap would show up).
>
> Now, I tried deriving my Finger class from QGraphicsWidget and overriding
> the paint() method. The large-size pixmaps work just fine, but now the
> Finger won't move around the scene, even when the debug output indicates
> that it should.
>
> Can anyone give me any pointers?
>
> ----------------------------------CODE
> START---------------------------------------
>
> #include <QDebug>
> #include <QPixmap>
> #include <QPainter>
> #include <QtPropertyAnimation>
>
> #include "finger.h"
>
> Finger::Finger(QGraphicsItem *parent)
> : QGraphicsWidget(parent)
> {
> qDebug() << "Finger::Finger() =>";
>
> m_xStart = -400;
> m_xOffset = 0;
> m_yOffset = 0;
>
> m_pixmap = new QPixmap("finger.png");
>
> qDebug() << "Finger::Finger() <=";
> }
>
> int Finger::xOffset()
> {
> return m_xOffset;
> }
>
> void Finger::setXOffset(int xOffset)
> {
> qDebug() << "::setXOffset xOffset >> " << xOffset;
> qDebug() << "::setXOffset comparison >> " << -m_xStart;
>
> /* if ( xOffset > -m_xStart )
> return;*/
>
> m_xOffset = xOffset;
> update();
> /*
> QTransform trans;
> trans.translate(m_xStart + m_xOffset,m_yOffset);
> setTransform(trans);
> */
> }
>
> void Finger::setViewHeight(int height)
> {
> m_yOffset = (height - size().height())/2;
> qDebug() << "image height:" << size().height();
> qDebug() << "image width:" << size().width();
> qDebug() << "yOffset:" << m_yOffset;
> /*
> QTransform trans;
> trans.translate(m_xStart + m_xOffset,m_yOffset);
> setTransform(trans);
> */
> }
>
> void Finger::returnToStartPosition()
> {
> QtPropertyAnimation *myAnim = new QtPropertyAnimation(this,
> "m_xOffset");
> myAnim->setDuration(300);
> myAnim->setEasingCurve(QtEasingCurve::OutCubic);
> myAnim->setStartValue(m_xOffset);
> myAnim->setEndValue(0);
> myAnim->start();
> }
>
> void Finger::paint(QPainter * painter, const QStyleOptionGraphicsItem *
> option, QWidget * widget)
> {
> Q_UNUSED(widget);
> Q_UNUSED(option);
>
> qDebug() << "x: " << m_xOffset;
>
> QTransform trans;
> trans.translate(m_xStart + m_xOffset,m_yOffset);
> painter->setTransform(trans);
>
> painter->drawPixmap(QPoint(0,0), *m_pixmap);
> }
>
>
> ---------------------------------CODE
> END--------------------------------------
>
> ------------------------OUTPUT START--------------------------
>
> MainWidget::MainWidget() =>
> MainScene::MainScene() =>
> MainScene::MainScene() <=
> Finger::Finger() =>
> Finger::Finger() <=
> MainWidget::MainWidget() <=
> x: 0
> x: 0
> ::setXOffset xOffset >> 1
> ::setXOffset comparison >> 400
> x: 1
> ::setXOffset xOffset >> 2
> ::setXOffset comparison >> 400
> x: 2
> ::setXOffset xOffset >> 3
> ::setXOffset comparison >> 400
> x: 3
> ::setXOffset xOffset >> 4
> ::setXOffset comparison >> 400
> x: 4
>
> ............................and so on
>
> -------------------------OUTPUT END--------------------------
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091103/6ee90542/attachment.html
More information about the Qt-interest-old
mailing list