·H
#include <QtQuick/QQuickPaintedItem>
#include <QColor>
#include <QLineF>
#include <QMutex>
class MyGraph : public QQuickPaintedItem
{
Q_OBJECT
protected:
virtual void componentComplete();
public:
MyGraph (QQuickPaintedItem *parent = 0);
void paint (QPainter *painter);
};
的.cpp
#include <QApplication>
#include <iostream>
#include <QPen>
#include "qpainter.h"
#include <QtQml/qqmlengine.h>
#include "graph.h"
MyGraph :: MyGraph (QQuickPaintedItem *parent) : QQuickPaintedItem (parent) {}
void MyGraph :: paint (QPainter *painter)
{
}
void MyGraph::componentComplete ()
{
QQuickPaintedItem::componentComplete ();
}
int main(int argc, char **argv)
{
QApplication app (argc, argv);
MyGraph g;
g.resize(200, 200);
g.show()
return app.exec();
}
错误:
:~/myQtGraph$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_QUICK_LIB -DQT_QML_LIB -DQT_WIDGETS_LIB -DQT_NETWORK_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/opt/Qt5.1.0/5.1.0/gcc_64/mkspecs/linux-g++ -I. -I. -I/opt/Qt5.1.0/5.1.0/gcc_64/include -I/opt/Qt5.1.0/5.1.0/gcc_64/include/QtQuick -I/opt/Qt5.1.0/5.1.0/gcc_64/include/QtQml -I/opt/Qt5.1.0/5.1.0/gcc_64/include/QtWidgets -I/opt/Qt5.1.0/5.1.0/gcc_64/include/QtNetwork -I/opt/Qt5.1.0/5.1.0/gcc_64/include/QtGui -I/opt/Qt5.1.0/5.1.0/gcc_64/include/QtCore -I. -o graph.o graph.cpp
graph.cpp:11:6: warning: unused parameter ‘painter’ [-Wunused-parameter]
graph.cpp: In function ‘int main(int, char**)’:
graph.cpp:26:5: error: ‘class MyGraph’ has no member named ‘resize’
graph.cpp:27:5: error: ‘class MyGraph’ has no member named ‘show’
make: *** [graph.o] Error 1
答案 0 :(得分:1)
不确定您搜索resize
和show
的原因,因为它们不是QQuickPaintedItem
的成员函数
如果您对调整大小感兴趣,请使用下面的代码。
使用QSize
定义尺寸并使用setContentsSize
进行设置。
MyGraph g;
QSize size;
size.setHeight(200);
size.setWidth(200);
g.setContentsSize(size);
或者,您可以使用resetHeight()
和resetWidth()