QT开发中文网

E:\YZYEdu\WhiteBoard\whiteboard.cpp:108: error: 'class QPaintDevice' has no member named 'size' QImage tempImage(painter.device()->size(), QImage::Format_ARGB32_Premultiplied); ^~~~

抱歉,看起来有些混淆。在 QPaintDevice 类中确实没有直接的 size() 方法。

如果您想获取当前绘图设备的大小,可以使用 QPainterdevice() 方法返回的指针调用 width()height() 方法来获取宽度和高度。请尝试以下修改:

if (m_drawing) {
    painter.setPen(m_pen);
    painter.fillRect(rect(), m_Color);
    
    // 绘制历史路径
    for (int i = 0; i <= currentPathIndex; ++i) {
        const QPainterPath& path = paths[i];
        const QPen& pen = pathPens[i];
        painter.setPen(pen);
        painter.drawPath(path);
    }
} else {
    // 创建一个临时的绘图设备
    QImage tempImage(painter.device()->width(), painter.device()->height(), QImage::Format_ARGB32_Premultiplied);
    QPainter tempPainter(&tempImage);
    
    // 将历史路径绘制到临时设备上
    for (int i = 0; i <= currentPathIndex; ++i) {
        const QPainterPath& path = paths[i];
        const QPen& pen = pathPens[i];
        tempPainter.setPen(pen);
        tempPainter.drawPath(path);
    }
    
    // 擦除当前路径
    const QPainterPath& erasePath = paths[currentPathIndex];
    const QPen& erasePen = pathPens[currentPathIndex];
    tempPainter.setCompositionMode(QPainter::CompositionMode_Clear);
    tempPainter.setPen(erasePen);
    tempPainter.drawPath(erasePath);

   // 将临时设备的内容绘制到主设备上,只有擦除部分会显示透明色
   painter.drawImage(QPoint(), tempImage); 
}

这样应该可以解决错误,并创建正确大小的临时绘图设备。如果还有其他问题,请随时提问。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://qt.0voice.com/?id=11982

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?