Qt - 创建 QPainter

发布于 2024-07-24 01:57:54 字数 502 浏览 9 评论 0原文

我正在尝试在程序中重写方法 paintEvent 并更改它。

void MainWindow::paintEvent(QPaintEvent *event)
{
    QRegion reg = this->bgPixmapHandle->rect();
    QPainter painter(this);

    painter.setClipRegion(reg);
    painter.drawImage(bgPixmapHandle->rect(), bgPixmapHandle);
    painter.end();
}

在这里,我尝试更改我的 bg 图像。 但我在线遇到错误:QPainter Painter(this);

错误:变量“QPainter画家”是 已初始化,尽管类型是 不完整

I'm trying to rewrite method paintEvent in my programm and change it.

void MainWindow::paintEvent(QPaintEvent *event)
{
    QRegion reg = this->bgPixmapHandle->rect();
    QPainter painter(this);

    painter.setClipRegion(reg);
    painter.drawImage(bgPixmapHandle->rect(), bgPixmapHandle);
    painter.end();
}

Here I try to change my bg image. But I got an error on line: QPainter painter(this);

Error: Variable 'QPainter painter' is
initialized, though the type is
incomplete

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

祁梦 2024-07-31 01:57:54

包含 QPainter 头文件。 QPainter 类仅在您包含在该翻译单元中的 Qt 标头之一中向前声明。

Include QPainter header file. QPainter class is only forward declared in one of the Qt headers you're including in that translation unit.

花间憩 2024-07-31 01:57:54
#include <QPainter>
#include <QPainter>
墨小墨 2024-07-31 01:57:54

你包括吗? Qt 非常喜欢前向声明类,这会导致此类神秘错误。

Are you including ? Qt is a big fan of forward declaration of classes, which causes such cryptic errors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文