在加载的 QPixmap 上使用 QPaint 绘图不起作用

问题描述 投票:0回答:1

我可以通过这样做在我的 Qlabel 上画一条线:

    QPixmap *myPixmap;
    myPixmap = new QPixmap();
    myPixmap->fill(Qt::red);
    QPainter painter(myPixmap);
    painter.setPen(Qt::blue);
    painter.drawLine(1, 1, 50, 50);
    ui.label->setPixmap(*myPixmap);

这有效。我得到一个带有蓝线的红色标签。

但现在我想在 1.jpg 上画一条线,如下所示:

    QPixmap *myPixmap;
    myPixmap = new QPixmap(ui.label->size());
    myPixmap->load("c:\\temp\\1.jpg");
    QPainter painter(myPixmap);
    painter.setPen(Qt::blue);
    painter.drawLine(1, 1, 50, 50);
    ui.label->setPixmap(*myPixmap);

不幸的是现在我只得到我的 1.jpg 但上面没有蓝线。

有人能解释一下吗? 我在Win10 / QT5.6.1 上工作

qt qpainter qpixmap
1个回答
0
投票

我希望发布答案是解释问题的正确方法。

感谢 @musicamante 和 @A.R.M 的评论,我发现蓝线在那里,但只是看不见,因为它对于主窗口来说太大了。不幸的是,我原来的 1.jpg 是单色的,所以我没有注意到这一点。

我在 1.jpg 中添加了一个框架,这样我现在可以用 2 个屏幕截图来显示我遇到的问题:

© www.soinside.com 2019 - 2024. All rights reserved.