• 5955阅读
  • 8回复

请问怎样设置图片的左右移动呢? [复制链接]

上一主题 下一主题
离线robertkun
 

只看楼主 正序阅读 楼主  发表于: 2009-06-02

本人想通过BUTTON 按钮的点击来实现图片的左右移动。。

请问该用怎样实现呢?谢谢。。

类似于这个:

                                              简单的生活使人快乐!
离线robertkun

只看该作者 8楼 发表于: 2009-06-10
引用第7楼mmmou2000于2009-06-09 16:24发表的  :
1)QPainter painter ?? try :  QPainter painter(this)
2)方法2 : paint的时候 修改matrix, 看qt 关于坐标系的解释


高手,我完全不知道你说是什么。。咆哮。。
                                              简单的生活使人快乐!
离线mmmou2000
只看该作者 7楼 发表于: 2009-06-09
1)QPainter painter ?? try :  QPainter painter(this)

2)方法2 : paint的时候 修改matrix, 看qt 关于坐标系的解释
离线robertkun

只看该作者 6楼 发表于: 2009-06-09
引用第5楼vvvfffddd于2009-06-07 22:00发表的  :
我刚开始学QT,请问mFlag是什么啊?能不能把代码完整显示呢?谢谢了!


mFlag 是我设置的一个标志变量。
                                              简单的生活使人快乐!
离线vvvfffddd
只看该作者 5楼 发表于: 2009-06-07
我刚开始学QT,请问mFlag是什么啊?能不能把代码完整显示呢?谢谢了!
离线robertkun

只看该作者 4楼 发表于: 2009-06-02
错误摆平了,现在我把它写在一个paintEvent()中,可是对paintEvent 的理解不是太透彻,
大家帮我分析一下为什么调用 drawPixmap ()函数没有起作用呢?该怎样调用呢?谢谢。。

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void PixmapTest::paintEvent( QPaintEvent * event)
{
    QPainter painter;
    if (mFlag==0)
    {
        QRectF target(10.0, 20.0, 80.0, 60.0);
        QRectF source(0.0, 0.0, 70.0, 40.0);
        painter.drawPixmap(target,mPixmap,source);
    }
    else
    {
        QRectF target(100.0, 200.0, 800.0, 600.0);
        QRectF source(0.0, 0.0, 70.0, 40.0);
        painter.drawPixmap(target,mPixmap,source);
    }
    update();
}
                                              简单的生活使人快乐!
离线robertkun

只看该作者 3楼 发表于: 2009-06-02
哪位大侠,帮忙分析一下这个错误吧:

void pixmapPainter::pixmapLeft()
{
    QRectF target(10.0, 20.0, 80.0, 60.0);
    QRectF source(0.0, 0.0, 70.0, 40.0);
    QPainter painter(this);
    painter.drawPixmap(target,pixmap,source);
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
错误如下:

1>pixmapPainter.cpp
1>.\pixmapPainter.cpp(26) : error C2664: 'void QPainter::drawPixmap(const QRectF &,const QPixmap &,const QRectF &)' : cannot convert parameter 2 from 'QPixmap *' to 'const QPixmap &'
1>        Reason: cannot convert from 'QPixmap *' to 'const QPixmap'
1>        No constructor could take the source type, or constructor overload resolution was ambiguous

谢谢了。。真是晕菜到家了。。唉。。
                                              简单的生活使人快乐!
离线robertkun

只看该作者 2楼 发表于: 2009-06-02
噢,是个思路啊,先谢谢了,谁还有更好的,也可以拿出来讨论讨论啊。。。
                                              简单的生活使人快乐!
离线feiying888

只看该作者 1楼 发表于: 2009-06-02
用绘图事件,画图片

下面这个函数画任意部分的图片。

void QPainter::drawPixmap ( int x, int y, const QPixmap & pixmap, int sx, int sy, int sw, int sh )

This is an overloaded member function, provided for convenience.

Draws a pixmap at (x, y) by copying a part of the given pixmap into the paint device.

(x, y) specifies the top-left point in the paint device that is to be drawn onto. (sx, sy) specifies the top-left point in pixmap that is to be drawn. The default is (0, 0).

(sw, sh) specifies the size of the pixmap that is to be drawn. The default, (0, 0) (and negative) means all the way to the bottom-right of the pixmap.


仅供参考
快速回复
限100 字节
 
上一个 下一个