使用 QPainter 绘图

发布于 2024-09-29 03:27:39 字数 298 浏览 2 评论 0原文

我需要使用 QPainter 进行绘制,但是当我尝试这样做时,

void paintEvent( QPaintEvent* )

我发现了错误:

QPainter::setPen:画家未激活

QPainter::setBrush:画家未激活

我可以在不在 void paintEvent( QPaintEvent* ) 中使用 QPainter 吗?

谢谢。

I need draw with QPainter, but when I try to do it not in

void paintEvent( QPaintEvent* )

I catch error:

QPainter::setPen: Painter not active

QPainter::setBrush: Painter not active

Can I use QPainter not in void paintEvent( QPaintEvent* ) ?

Thank you.

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

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

发布评论

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

评论(1

翻身的咸鱼 2024-10-06 03:27:39

您正在使用一个小部件作为 QPainter 的绘画设备。在这种情况下,QPainter 通常只能在小部件的绘制事件的上下文中使用。 QPainter 文档对此有以下说明:

警告:当绘画设备是
widget,只能使用QPainter
在 PaintEvent() 函数中或在
由paintEvent()调用的函数;那
是除非
Qt::WA_PaintOutsidePaintEvent 小部件
属性已设置。在 Mac OS X 和
Windows,你只能在一个
PaintEvent() 函数无论
该属性的设置。

通过为 QPainter 设置另一个绘画设备(例如 QPixmap),可以在绘画事件之外使用 QPainter

You are using a widget as the paint device for QPainter. In this case, QPainter can usually only be used within the context of the widget's paint event. The QPainter documentation has the following to say about this:

Warning: When the paintdevice is a
widget, QPainter can only be used
inside a paintEvent() function or in a
function called by paintEvent(); that
is unless the
Qt::WA_PaintOutsidePaintEvent widget
attribute is set. On Mac OS X and
Windows, you can only paint in a
paintEvent() function regardless of
this attribute's setting.

It is possible to use QPainter outside a paint event by setting another paint device for QPainter, for example a QPixmap.

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