QRectF Grafik::boundingRect() const{ return QRectF(0, 0, my_model->rowCount()+10, size_y);}
QPainterPath Grafik::shape() const{ QPainterPath path; path.addRect(1, 1, size_x, size_y); return path;}
void Grafik::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){ Q_UNUSED(widget); QColor fillColor = (option->state & QStyle::State_Selected) ? color.dark(150) : color; if (option->state & QStyle::State_MouseOver) fillColor = fillColor.light(125); const qreal lod = option->levelOfDetailFromTransform(painter->worldTransform()); QVarLengthArray<QPointF> pointsss; QList<double> x; for (int i = 0; i <= size_x-1; i++) { x.append(my_model->item(i, stolbec)->text().toFloat()); pointsss.append(QPointF(i,x[i])); } painter->setPen(QPen(color, 2)); painter->drawPoints(pointsss.data(), pointsss.size());}
C++ (Qt)bool QGraphicsItem::collidesWithPath ( const QPainterPath & path, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape ) const
QGraphicsItem *item = new Grafik(model, Qt::red, 3, min, max); item->setPos(QPointF(0, 200)); item->setFlag(QGraphicsItem::ItemIsMovable, true);
bool QGraphicsItem::collidesWithPath ( const QPainterPath & path, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape ) const
void Grafik::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){ ... const qreal lod = option->levelOfDetailFromTransform(painter->worldTransform()); QVarLengthArray<QPointF> pointsss; QList<double> x; for (int i = 0; i <= size_x-2; i++) { x.append(my_model->item(i, stolbec)->text().toFloat()); pointsss.append(QPointF(i,x[i])); path1.moveTo(i,x[i]); path1.lineTo(i+1, my_model->item(i+1, stolbec)->text().toFloat()); } painter->setPen(QPen(color, 2)); painter->drawPoints(pointsss.data(), pointsss.size()); painter->setPen(QPen(Qt::blue,15)); //painter->drawPath(path1);}
QPainterPath Grafik::shape() const{ //QPainterPath path1; // path.addRect(1, 1, size_x, size_y/2); return path1;}
void Grafik::mousePressEvent(QGraphicsSceneMouseEvent *event){ QGraphicsItem::mousePressEvent(event); QGraphicsItem::setCursor(Qt::ClosedHandCursor); update();}
void Grafik::mouseMoveEvent(QGraphicsSceneMouseEvent *event){ QGraphicsItem::setCursor(Qt::ClosedHandCursor); QGraphicsItem::mouseMoveEvent(event); if (QGraphicsItem::pos().x()!=0) // zapret peremesheniya po X { QGraphicsItem::setX(0); } update(); }
void Grafik::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ QGraphicsItem::setCursor(Qt::OpenHandCursor); QGraphicsItem::mouseReleaseEvent(event); update();}
C++ (Qt)bool QGraphicsItem::collidesWithPath ( const QPainterPath & path, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape ) const [virtual]
C++ (Qt)//это проверка на клик будетif (path.elementCount() == 1){ QPointF pos = path.elementAt(0); //дальше определяешь попадает ли в область (элементарная геометрия) if ( ... ) return true; return false;} //возвращаешь пересечение со свои путемreturn path.intersects( ... );
C++ (Qt)void QGraphicsItem::setCursor ( const QCursor & cursor )
C++ (Qt)void QGraphicsItem::setTransform ( const QTransform & matrix, bool combine = false )
C++ (Qt)void QGraphicsItem::prepareGeometryChange () [protected]