48 lines
1.6 KiB
C++
48 lines
1.6 KiB
C++
#ifndef CUSTOMELLIPSE_H
|
|
#define CUSTOMELLIPSE_H
|
|
#include <qcustomplot.h>
|
|
|
|
class CustomEllipse : public QCPItemEllipse
|
|
{
|
|
public:
|
|
CustomEllipse(QCustomPlot *parentPlot) : QCPItemEllipse(parentPlot) {}
|
|
|
|
// 重写绘制函数
|
|
virtual void draw(QCPPainter *painter) override
|
|
{
|
|
// 自定义绘制代码
|
|
//painter->setPen(QPen(Qt::blue, 2)); // 例如,改变边框颜色和宽度
|
|
//painter->setBrush(QBrush(Qt::green)); // 改变填充颜色
|
|
QCPItemEllipse::draw(painter); // 调用基类的绘制函数
|
|
return;
|
|
|
|
QPointF p1 = topLeft->pixelPosition();
|
|
//QPointF p2 = bottomRight->pixelPosition();
|
|
QPointF p2 = QPointF(p1.rx()+5, p1.ry()+5);
|
|
if (p1.toPoint() == p2.toPoint()) {
|
|
return;
|
|
}
|
|
QRectF ellipseRect = QRectF(p1, p2).normalized();
|
|
const int clipEnlarge = qCeil(mainPen().widthF());
|
|
QRect clip = clipRect().adjusted(-clipEnlarge, -clipEnlarge, clipEnlarge, clipEnlarge);
|
|
if (ellipseRect.intersects(clip)) { // only draw if bounding rect of ellipse is visible in cliprect
|
|
painter->setPen(mainPen());
|
|
painter->setBrush(mainBrush());
|
|
#ifdef __EXCEPTIONS
|
|
try { // drawEllipse sometimes throws exceptions if ellipse is too big
|
|
#endif
|
|
painter->drawEllipse(ellipseRect);
|
|
#ifdef __EXCEPTIONS
|
|
} catch (...) {
|
|
qDebug() << Q_FUNC_INFO << "Item too large for memory, setting invisible";
|
|
setVisible(false);
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
|
|
// 可以添加更多自定义方法或属性
|
|
};
|
|
|
|
#endif // CUSTOMELLIPSE_H
|