Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 无法在Qt中添加多个graphicsitem_C++_Qt_Paint_Qgraphicsitem - Fatal编程技术网

C++ 无法在Qt中添加多个graphicsitem

C++ 无法在Qt中添加多个graphicsitem,c++,qt,paint,qgraphicsitem,C++,Qt,Paint,Qgraphicsitem,我试图在点击鼠标后在Graphicscene中绘制多个点。点类继承自QGraphicsItem类。下面的代码分别显示绘画和鼠标事件 void point:: paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){ if(mPaintFlag){ QPen paintpen(Qt::red); paintpen.setWidth(4); QPointF p1;

我试图在点击鼠标后在Graphicscene中绘制多个点。点类继承自
QGraphicsItem
类。下面的代码分别显示绘画和鼠标事件

void point:: paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
if(mPaintFlag){
    QPen paintpen(Qt::red);
    paintpen.setWidth(4);

    QPointF p1;
    p1.setX(x1);
    p1.setY(y1);

    painter->setPen(paintpen);
    painter->drawPoint(p1);
    update();
   }
}

void point::mousePressEvent(QGraphicsSceneMouseEvent *e)
{
if(e->button()==Qt::LeftButton) {
    if(mClick){
        x1 = e->pos().x();
        y1 = e->pos().y();

        mClick = false;
        mPaintFlag = true;
        update();
    }
    _store.set_point(e->pos());
    store_point.push_back(_store);
    qDebug() << _store.getValue();
    qDebug() << "Size of vector =" << store_point.size();
    update();
}
void point::paint(QPainter*painter,const QStyleOptionGraphicsItem*选项,QWidget*小部件){
if(mPaintFlag){
QPen油漆笔(Qt::红色);
画笔设置宽度(4);
QPointF p1;
p1.setX(x1);
p1.setY(y1);
画师->设置画笔(画笔);
油漆工->绘图点(p1);
更新();
}
}
无效点::MousePresseEvent(QGraphicsSceneMouseEvent*e)
{
如果(e->button()==Qt::LeftButton){
if(mClick){
x1=e->pos().x();
y1=e->pos().y();
mClick=false;
mPaintFlag=true;
更新();
}
_store.set_点(e->pos());
存储点。向后推(存储);

qDebug()你的函数_存储什么。set_point(e->pos())做什么?你在哪里向Qgraphicscene添加点?注意,你不需要从paint函数调用update()。update()也在paint函数中调用。正如你可能看到的,我已经在if条件下实现了。或者我应该以不同的方式来实现吗?