当前位置: 技术问答>linux和unix
qpainter中的问题
来源: 互联网 发布时间:2016-03-26
本文导语: #include #include #include #include #include #include class DrawView : public QWidget { public: DrawView() { setBackgroundColor(Qt::white); } protected: void drawColorWheel(QPainter*); void paintEvent(QPaintEvent*); }; void D...
#include
#include
#include
#include
#include
#include
class DrawView : public QWidget
{
public:
DrawView()
{
setBackgroundColor(Qt::white);
}
protected:
void drawColorWheel(QPainter*);
void paintEvent(QPaintEvent*);
};
void DrawView::drawColorWheel(QPainter *p)
{
QFont f("times", 18, QFont::Bold);
p->setFont(f);
p->setPen(Qt::black);
p->setWindow(0, 0, 500, 500); // defines coordinate system
for (int i = 0; i setWorldMatrix(matrix); // use this world matrix
QColor c;
c.setHsv(i*10, 255, 255); // rainbow effect
p->setBrush(c); // solid fill with color c
p->drawRect(70, -10, 80, 10); // draw the rectangle
QString n;
n.sprintf("H=%d", i*10);
p->drawText(80+70+5, 0, n); // draw the hue number
}
}
void DrawView::paintEvent(QPaintEvent*)
{
QPainter p(this);
drawColorWheel(&p);
}
int main(int argc, char **argv)
{
QApplication app(argc, argv);
DrawView draw;
draw.show();
return app.exec();
}
------ 已启动生成: 项目: qpaint, 配置: Debug Win32 ------
正在编译...
qpaint.cpp
.qpaint.cpp(12) : error C3861: “setBackgroundColor”: 找不到标识符
.qpaint.cpp(29) : error C2039: “setWorldMatrix”: 不是“QPainter”的成员
c:qt4.1.0includeqtgui../../src/gui/painting/qpainter.h(56) : 参见“QPainter”的声明
生成日志保存在“file://c:qpaintdebugBuildLog.htm”
qpaint - 2 个错误,0 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========
#include
#include
#include
#include
#include
class DrawView : public QWidget
{
public:
DrawView()
{
setBackgroundColor(Qt::white);
}
protected:
void drawColorWheel(QPainter*);
void paintEvent(QPaintEvent*);
};
void DrawView::drawColorWheel(QPainter *p)
{
QFont f("times", 18, QFont::Bold);
p->setFont(f);
p->setPen(Qt::black);
p->setWindow(0, 0, 500, 500); // defines coordinate system
for (int i = 0; i setWorldMatrix(matrix); // use this world matrix
QColor c;
c.setHsv(i*10, 255, 255); // rainbow effect
p->setBrush(c); // solid fill with color c
p->drawRect(70, -10, 80, 10); // draw the rectangle
QString n;
n.sprintf("H=%d", i*10);
p->drawText(80+70+5, 0, n); // draw the hue number
}
}
void DrawView::paintEvent(QPaintEvent*)
{
QPainter p(this);
drawColorWheel(&p);
}
int main(int argc, char **argv)
{
QApplication app(argc, argv);
DrawView draw;
draw.show();
return app.exec();
}
------ 已启动生成: 项目: qpaint, 配置: Debug Win32 ------
正在编译...
qpaint.cpp
.qpaint.cpp(12) : error C3861: “setBackgroundColor”: 找不到标识符
.qpaint.cpp(29) : error C2039: “setWorldMatrix”: 不是“QPainter”的成员
c:qt4.1.0includeqtgui../../src/gui/painting/qpainter.h(56) : 参见“QPainter”的声明
生成日志保存在“file://c:qpaintdebugBuildLog.htm”
qpaint - 2 个错误,0 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========
|
你的系统安装的是Qt4吧?
|
这个问题就应该是QT3和QT4的版本问题了,一些库QT3里支持,但QT4不支持,你在.pro文件里的install行前加QT += qt3support试试