QPainter镜像不起作用

时间:2015-03-31 08:28:36

标签: qt merge qpainter mirror

我有一个类似于paint的程序,我有一个更改请求:

添加一个名为镜像模式的新功能,在镜像模式下,画布按左右两半划分。在其中一半中绘制的所有图片都应镜像到另一半。

我添加了代码,以便显示镜像部分;但是原始图像似乎不是由QPainter绘制的。是否有一件简单的事情让我无法让QPainter同时显示镜像和绘制的图像。相关的源代码如下:

//
void ImageArea::paintEvent(QPaintEvent *event)
{
    QPainter *painter = new QPainter();
    painter->begin(this);

    QRect *rect = new QRect(event->rect());

    painter->setBrush(QBrush(QPixmap(":media/textures/transparent.jpg")));
    painter->drawRect(0, 0,
                  mImage->rect().right() - 1,
                  mImage->rect().bottom() - 1);


    painter->drawImage(event->rect(), *mImage, event->rect());
    painter->setPen(Qt::NoPen);
    painter->setBrush(QBrush(Qt::black));
    painter->drawRect(QRect(mImage->rect().right(),
                            mImage->rect().bottom(), 6, 6));
    painter->drawImage(event->rect(), *mImage, event->rect());
    painter->end();
    painter->begin(this);

    QImage tmp(mImage->mirrored(true,false));
    painter->drawImage(0, 0, tmp);
    painter->end();



}

0 个答案:

没有答案