• 11709阅读
  • 4回复

使用QPainter老是Paint device returned engine == 0, type: 1 [复制链接]

上一主题 下一主题
离线shj123
 
只看楼主 倒序阅读 楼主  发表于: 2009-09-17
一直不成功,不能画图,显示说Paint device returned engine == 0, type: 1

请教下是什么原因?
离线shj123
只看该作者 1楼 发表于: 2009-09-17
找到一篇相关的帖子,难道在paintEvent之外画图,windows版QT运作不能?

http://www.qtcentre.org/forum/f-qt-programming-2/t-qt41wing-using-qpainter-outside-paintevent-493.html


代码如下:

STabWidget是QTabWidget的子类


#include <QPainter>
#include "STabWidget.h"

STabWidget::STabWidget(QWidget* parent)
        : QTabWidget(parent)
{
    QWidget* dummy = new QWidget;
    addTab(dummy, "welcome");
    dummy->setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
    QPainter p(dummy);
    p.drawText(0, 0, "123");
    resize(250, height());
}
离线dbzhang800

只看该作者 2楼 发表于: 2009-09-17
manual 中说的很清楚

QPainter Class Reference

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.
离线robertkun

只看该作者 3楼 发表于: 2009-09-17
                                              简单的生活使人快乐!
离线voidbroken

只看该作者 4楼 发表于: 2011-03-10
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.
快速回复
限100 字节
 
上一个 下一个