QGroupBox的六边形形状边界

时间:2017-01-19 23:07:57

标签: c++ qt qgroupbox

是否可以将QGroupBox的边界重新绘制为六边形的形状 而不是矩形?

更新: 我能够画出六边形QGroupBox。我可以在boudingrect之外画画,或者以某种方式可以放大boundingrect ??

QPainterPath MyGroupBox::getHexagonPath( const QPointF &pos,
                                  const QSizeF &size )
{     
    QPainterPath path;

    const double cos30 = 0.866025; 

    const double dx = 0.25 * size.width() - pos.x();  // 0.5 * size.width() - cos30;
    const double dy = 0.5  * size.height() - pos.y() - cos30;

    double x1 = pos.x(); // - 2 * dx;
    double y1 = pos.y(); // - dy;

    const double x2 = x1 + 1 * dx;
    const double x3 = x1 + 3 * dx;
    const double x4 = x4 + 4 * dx;

    const double y2 = y1 + 1 * dy;
    const double y3 = y1 + 2 * dy;

    QPolygonF hexagon;
    hexagon += QPointF( x1, y2 );
    hexagon += QPointF( x2, y1 );
    hexagon += QPointF( x3, y1 );
    hexagon += QPointF( x4, y2 );
    hexagon += QPointF( x3, y3 );
    hexagon += QPointF( x2, y3 );

    path.addPolygon( hexagon );        
    path.closeSubpath();
    return path;
}

0 个答案:

没有答案