void LineItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget){ Q_UNUSED(widget); painter->setClipRect( item->exposedRect ); QPen oldPen = painter->pen(); if (is_selected_) { QPen dash_pen_background; dash_pen_background.setColor(Qt::white); dash_pen_background.setWidth(width_); QPen dash_pen; dash_pen.setColor(Qt::black); dash_pen.setWidth(width_); dash_pen.setDashOffset(dash_offset_); dash_pen.setDashPattern(dash_pattern_); int offset; if (is_highlighted_) { offset = width_; } else { offset = width_/2; } painter->setPen(dash_pen_background); if (boundingRect().width() >= boundingRect().height()) { painter->drawLine(start_.x(), start_.y() - offset, finish_.x(), finish_.y() - offset); painter->drawLine(finish_.x(), finish_.y() + offset, start_.x(), start_.y() + offset); painter->setPen(dash_pen); painter->drawLine(start_.x(), start_.y() - offset, finish_.x(), finish_.y() - offset); painter->drawLine(finish_.x(), finish_.y() + offset, start_.x(), start_.y() + offset); } else { // полностью аналогичный предыдущему блоку код, только смещение по x, а не по y. } } QPen pen; pen.setColor(color_); pen.setWidth(width_); painter->setPen(pen); painter->drawLine(start_,finish_); painter->setPen(oldPen);}