Qt二維繪圖之改變Item的選中時的邊框

void  RectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    QStyleOptionGraphicsItem op;
    op.initFrom(widget);

//     // 判斷選中時,設置狀態爲 State_None
    if (option->state & QStyle::State_Selected){


        qreal itemPenWidth = 10;
        const qreal pad = itemPenWidth / 2;
        const qreal penWidth = 0;

        // 邊框區域顏色
        QColor color = QColor(Qt::red);

        //繪製實現
        painter->setPen(QPen(color, penWidth, Qt::SolidLine));
        painter->setBrush(Qt::NoBrush);
        painter->drawRect(boundingRect().adjusted(pad, pad, -pad, -pad));

        // 繪製虛線
        painter->setPen(QPen(color, 0, Qt::DashLine));
        painter->setBrush(Qt::NoBrush);
        painter->drawRect(boundingRect().adjusted(pad, pad, -pad, -pad));
        qDebug() << "選中";
    }else{

    }

    //繪製圖標,必須小於邊框矩形
    painter->setRenderHint( QPainter::Antialiasing );
    painter->drawRect(m_x, m_y, m_w, m_h);



}

相關文章
相關標籤/搜索