Skip to content

Commit 28590de

Browse files
committed
rounded tooltip rect
1 parent 81e02c8 commit 28590de

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

qdataflowcanvas.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ void QDataflowNodeTextLabel::complete()
926926
QDataflowTooltip::QDataflowTooltip(QDataflowCanvas *canvas_, QString text, QPointF offset)
927927
: offset_(offset)
928928
{
929-
shape_ = new QGraphicsPolygonItem(this);
929+
shape_ = new QGraphicsPathItem(this);
930930
shape_->setPen(QPen(Qt::black, 1, Qt::SolidLine));
931931
shape_->setBrush(Qt::white);
932932

@@ -947,22 +947,15 @@ void QDataflowTooltip::adjust()
947947
{
948948
const int kb = 4;
949949
QRectF br = text_->boundingRect().adjusted(-kb, -kb, kb, kb);
950-
951-
// anchor on bottom side
952-
qreal y = br.bottom();
953-
qreal x = 0.5 * (br.left() - br.right()) + br.right();
954-
const int kw = 6;
955-
956-
QPolygonF p;
957-
p << offset_;
958-
p << QPointF(x - kw, y);
959-
p << br.bottomLeft();
960-
p << br.topLeft();
961-
p << br.topRight();
962-
p << br.bottomRight();
963-
p << QPointF(x + kw, y);
964-
p << offset_;
965-
shape_->setPolygon(p);
950+
QPointF hoff(6, 0);
951+
QPainterPath pTip;
952+
pTip.moveTo(offset_);
953+
pTip.lineTo(br.center() - hoff);
954+
pTip.lineTo(br.center() + hoff);
955+
pTip.closeSubpath();
956+
QPainterPath pRect;
957+
pRect.addRoundedRect(br, 1.5 * kb, 1.5 * kb);
958+
shape_->setPath(pTip.united(pRect).simplified());
966959
}
967960

968961
void QDataflowTextCompletion::complete(QString nodeText, QStringList &completionList)

qdataflowcanvas.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ class QDataflowTooltip : public QGraphicsItemGroup
299299

300300
private:
301301
QGraphicsSimpleTextItem *text_;
302-
QGraphicsPolygonItem *shape_;
302+
QGraphicsPathItem *shape_;
303303
QPointF offset_;
304304

305305
friend class QDataflowCanvas;

0 commit comments

Comments
 (0)