0

I have a QGraphicsWidget that represents a line on a map. The object disappears when a small portion of the bottom of the bounding rectangle moves out of the scene. It also disappears when part of the right side of it's bounding rectangle goes out of the scene. Below is a illustration of what is happening.

The green box is the bounding rect as drawn from the object's paint function.

Object is visible

Now I pan the scene so that only this much of the object is visible. It is still in view. However, if I pan any more to the right, the object disappears despite having half of it's bounding rect still in the viewport.

Object will disappear if panned one more pixel right.

The same thing happens when panning down so that the bottom of the object is leaving the viewport. If I pan any more down than below, the object disappears.

enter image description here

Here is the paint function:

void AirwayGraphicsWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {


    QPen pen(m_aw_obj->AltitudeType() == stds::rdb::WPAltitudeTypes::HIGH ? COLOR_HI_AIRWAY :
    m_aw_obj->AltitudeType() == stds::rdb::WPAltitudeTypes::LOW ? COLOR_LO_AIRWAY :
    COLOR_BOTH_AIRWAY);

    pen.setWidth(3);
    pen.setCosmetic(true);
    painter->setPen(pen);
    painter->drawPolyline(m_points.data(), m_points.size());

    pen.setColor(m_is_hovered ? Qt::red : Qt::green);
    pen.setWidth(0);
    painter->setPen(pen);
    painter->drawRect(boundingRect());
}

Any ideas about what is going on here? I've been messing with it for a couple of days and I'm out of things to try.

Update Constructor

AirwayGraphicsWidget::AirwayGraphicsWidget(const stds::rdb::model::EnrouteAirway* aw, QGraphicsItem* parent)
: RDBEntityGraphicsWidget(aw, parent)
, m_bounding_rect()
, m_aw_obj(aw)
, m_lod(LevelOfDetail::NONE)
, m_is_hovered(false)
{

    double highest_lat = std::numeric_limits<double>::lowest();
    double lowest_lat  = std::numeric_limits<double>::max();
    double highest_lon = std::numeric_limits<double>::lowest();
    double lowest_lon  = std::numeric_limits<double>::max();

    for (auto &awd : m_aw_obj->AirwayData()) {
        if (-awd.entity->Pos().latitude_deg > highest_lat) {
            highest_lat = -awd.entity->Pos().latitude_deg;
        }

        if (-awd.entity->Pos().latitude_deg < lowest_lat) {
            lowest_lat = -awd.entity->Pos().latitude_deg;
        }

        if (awd.entity->Pos().longitude_deg > highest_lon) {
            highest_lon = awd.entity->Pos().longitude_deg;
        }

        if (awd.entity->Pos().longitude_deg < lowest_lon) {
            lowest_lon = awd.entity->Pos().longitude_deg;
        }

        m_points.push_back(QPointF(awd.entity->Pos().longitude_deg, -awd.entity->Pos().latitude_deg));
}
    highest_lat += 5.0 * geom::NM_TO_DEG;
    lowest_lat  -= 5.0 * geom::NM_TO_DEG;
    highest_lon += 5.0 * geom::NM_TO_DEG;
    lowest_lon  -= 5.0 * geom::NM_TO_DEG;
    prepareGeometryChange();
    m_bounding_rect = QRectF(QPointF(highest_lon, highest_lat), QPointF(lowest_lon, lowest_lat));

    setPreferredHeight(m_bounding_rect.height());
    setPreferredWidth(m_bounding_rect.width());

    setAcceptHoverEvents(true);
}

QRectF AirwayGraphicsWidget::boundingRect() const { return m_bounding_rect; }
4

0 回答 0