• NodeAndLink.rar

    Qt 场景、视图、项应用实例,Qt整套源码,喜欢请下载: Link: #include <QGraphicsLineItem> class Node; class Link : public QGraphicsLineItem { public: Link(Node *formN, Node *toN); ~Link(); inline Node *formNode()const { return myFormNode; } inline Node *toNode() const { return myToNode; } void setColor(const QColor &c); QColor color()const; void trackNodes(); private: Node *myFormNode; Node *myToNode; }; Node: #ifndef NODE_H #define NODE_H #include <QGraphicsItem> #include <QSet> class Link; class Node : public QGraphicsItem { public: Node(); ~Node(); inline void setText(const QString &text;); inline QString text()const {return myText;} inline void setTextColor(const QColor &c) { myTextColor = c; update();} inline QColor textColor()const{return myTextColor;} inline void setBackgroundColor(const QColor &c) { myBackgroundColor = c; update();} inline QColor backgroundColor()const{return myBackgroundColor;} inline void setOutLineColor(const QColor &c) { myOutLineColor = c; update();} inline QColor outLineColor()const{return myOutLineColor;} void addLink(Link *l); void removeLink(Link *l); QRectF boundingRect()const Q_DECL_OVERRIDE; QPainterPath shape() const Q_DECL_OVERRIDE; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR) Q_DECL_OVERRIDE; protected: void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE; QVariant itemChange(GraphicsItemChange change, const QVariant &value;) Q_DECL_OVERRIDE; private: QRectF outlineRect()const; int roundness(double size)const;//计算圆角 QSet&lt;Link *&gt; myLinks; QString myText; QColor myTextColor; QColor myBackgroundColor; QColor myOutLineColor; }; #endif // NODE_H View: #ifndef GRAPHICSVIEW_H #define GRAPHICSVIEW_H #include <QWidget> #include <QGraphicsView> #include <QGraphicsScene> class GraphicsView : public QGraphicsView { Q_OBJECT public: explicit GraphicsView(QGraphicsScene *scene, QWidget *parent = 0); protected: void wheelEvent(QWheelEvent *e); }; #endif // GRAPHICSVIEW_H

    0
    120
    1.26MB
    2019-07-11
    6
  • TestPainter.rar

    QPainter应用实例复古计时器旋钮源码: 如下:通过重载 void OvenTimer::paintEvent(QPaintEvent *event) 事件,实现如上的旋钮绘制: void OvenTimer::draw(QPainter *p) { static const int t[3][2] = {{-2, -49}, {+2, -49}, {0, -47}};   QPen tckP(palette().foreground(), 1.5); QPen tinPen(palette().foreground(), 0.5); QColor nice(150,150,200);   p->setPen(tinPen); p->setBrush(palette().foreground()); p->drawPolygon(QPolygon(3, &t[0][0]));   QConicalGradient c(0,0,-90.0); c.setColorAt(0.0,Qt::darkGray); c.setColorAt(0.2,nice); c.setColorAt(0.5,Qt::white); c.setColorAt(1.0,Qt::darkGray);   p->setBrush(c); p->drawEllipse(-46,-46,92,92);   QRadialGradient h(0,0,20,0,0); h.setColorAt(0.0,Qt::lightGray); h.setColorAt(0.2,Qt::darkGray); h.setColorAt(0.5,Qt::white); h.setColorAt(1.0,Qt::black);   p->setPen(Qt::NoPen); p->setBrush(h); p->drawEllipse(-20,-20,40,40);   QLinearGradient k(-7,-25,7,-25); k.setColorAt(0.0,Qt::black); k.setColorAt(0.2,nice); k.setColorAt(0.3,Qt::lightGray); k.setColorAt(0.8,Qt::white); k.setColorAt(1.0,Qt::black);   p->rotate(duration() * DegreesPerSecond); p->setBrush(k); p->setPen(tinPen); p->drawRoundRect(-7,-25,14,50,90,49);     for(int i = 0; i <= MaxMinutes; i++) { if(i % 5 == 0) { p->setPen(tckP); p->drawLine(0, -41, 0, -44); p->drawText(-15, -41,30,30, Qt::AlignHCenter|Qt::AlignTop, QString::number(i)); } else { p->setPen(tinPen); p->drawLine(0,-42, 0, -44); }   p->rotate(-DegreesPerMinute); } } void OvenTimer::paintEvent(QPaintEvent *event) { Q_UNUSED(event); QPainter p(this); p.setRenderHint(QPainter::Antialiasing, true); int side = qMin(width(), height()); p.setViewport((width() - side) / 2, (height() - side)/2, side, side); p.setWindow(-50,-50,100,100); draw(&p); } 需要实现源码,请留言!

    0
    134
    914KB
    2019-07-11
    13
  • 创作能手

    授予每个自然周发布1篇到3篇原创IT博文的用户
关注 私信
上传资源赚积分or赚钱