class SliderCrankLinkage : public QWidget{ Q_OBJECTpublic: explicit SliderCrankLinkage(QWidget *parent = nullptr);protected: void paintEvent(QPaintEvent* e);};
void SliderCrankLinkage::paintEvent(QPaintEvent *e){ Q_UNUSED(e); QPainter pbearing(this); pbearing.setPen(QPen(Qt::black, 5, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); QLine AB(0, 0, 60, 0), BC(0, 0, 60, 0), CA(0, 0, 60, 0); QTransform transform; transform.translate(150, 150); pbearing.setWorldTransform(transform); pbearing.drawEllipse(-40, -40, 80, 80); pbearing.drawEllipse(-25, -25, 50, 50); transform.rotate(+60.0); pbearing.setWorldTransform(transform); pbearing.drawLine(AB); transform.rotate(+60.0); pbearing.setWorldTransform(transform); pbearing.drawLine(BC); transform.rotate(-60.0); transform.translate(60.0, 0); transform.rotate(+120.0); pbearing.setWorldTransform(transform); pbearing.drawLine(CA); transform.translate(30.0, 0); pbearing.setWorldTransform(transform); pbearing.drawLine(50, 0, -50, 0); pbearing.setPen(Qt::NoPen); pbearing.setBrush(QBrush(Qt::black, Qt::BDiagPattern)); pbearing.drawRect(50, 0, -100, -25);}