70 lines
1.9 KiB
C++
70 lines
1.9 KiB
C++
#ifndef MYCUSTOMGRAPHICSITEM_H
|
|
#define MYCUSTOMGRAPHICSITEM_H
|
|
|
|
#include <QObject>
|
|
#include <QWidget>
|
|
#include <QMouseEvent>
|
|
#include <QGraphicsScene>
|
|
#include <QGraphicsRectItem>
|
|
#include <QGraphicsSceneMouseEvent>
|
|
#include <QRect>
|
|
#include <QPainter>
|
|
#include <QPolygon>
|
|
#include <QList>
|
|
#include <QTransform>
|
|
|
|
|
|
class CMyCustomGraphicsItem : public QObject , public QGraphicsItemGroup
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit CMyCustomGraphicsItem(QObject *parent = nullptr);
|
|
|
|
// void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
|
// void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
|
// void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
|
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
|
void wheelEvent(QGraphicsSceneWheelEvent *event);
|
|
signals:
|
|
void doubleclick(QGraphicsSceneMouseEvent *event);
|
|
public slots:
|
|
|
|
//protected:
|
|
// void mousePressEvent(QGraphicsSceneMouseEvent* event) override {
|
|
// // 当鼠标按下时,切换选中状态
|
|
// isSelected = !isSelected;
|
|
// update(); // 触发重绘
|
|
// }
|
|
|
|
// void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override {
|
|
// QGraphicsItemGroup::paint(painter, option, widget);
|
|
|
|
// if (isSelected) {
|
|
// // 如果项被选中,绘制一个高亮边框
|
|
// painter->setPen(QPen(Qt::red));
|
|
// painter->drawRoundRect(boundingRect());
|
|
// }
|
|
// }
|
|
|
|
//private:
|
|
// bool isSelected = false; // 是否被选中
|
|
};
|
|
class LineItem : public QGraphicsItem
|
|
{
|
|
public:
|
|
LineItem();
|
|
|
|
//最大显示范围的设置默认为30
|
|
float maxX();
|
|
void setMaxX(float value);
|
|
public:
|
|
QRectF boundingRect() const;
|
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
|
private:
|
|
//显示范围
|
|
float m_maxX;
|
|
};
|
|
|
|
#endif // MYCUSTOMGRAPHICSITEM_H
|