Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Mysterious flickering arrow
Qt 6.11 is out! See what's new in the release blog

Mysterious flickering arrow

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    deanc
    wrote on last edited by
    #1

    I'm trying to draw a multi-segment line with an arrow at one end. I have a class derived from QGraphicsPathItem that has a QPolygonF member. For the line I'm building the path, then create the points for the arrow based on the last two points of the line segment (to get the rotation and position).

    It all works, except that when the arrow polygon is drawn, every other re-draw is not filled. Here's the paint code:
    @void NodeConnector::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
    {
    QGraphicsPathItem::paint(painter, option, widget);
    painter->setBrush(Qt::SolidPattern);
    painter->drawPolygon(arrow);
    }
    @

    Here's how the polygon is set up:
    @
    void NodeConnector::setArrow(QPointF & from, QPointF & to)
    {
    static QPolygonF arrowHead;
    arrowHead << QPointF(0.0, 0.0) << QPointF(12, 4) << QPointF(12, -4);// << QPointF(0,0);

    QPointF diff = from - to;
    double angle = atan2(diff.y(), diff.x());                   // This is the angle relative to west-pointing
    double cosang = cos(angle);
    double sinang = sin(angle);
    //
    // Create temporary, rotate arrow
    arrow.clear();
    for (int i = 0; i < arrowHead.size(); ++i) {
        qreal x = arrowHead.at(i).x() * cosang - arrowHead.at(i).y() * sinang + to.x();
        qreal y = arrowHead.at(i).y() * cosang + arrowHead.at(i).x() * sinang + to.y();
        arrow << QPointF(x,y);
    }
    

    }
    @
    So far every variation I've tried (changing the class to a QGraphicsItem with a line and polygon, making the arrow a separate QGraphicsItem) makes no difference; every other redraw, the arrow is just an outline. I'm pretty new to Qt so I'm sure I'm just missing something fundamental.

    Thanks.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved