Qt繪製三維圖形–餅圖

來源:互聯網
上載者:User

http://www.qtcn.org/bbs/read-htm-tid-53074.html

void aaq::paintEvent( QPaintEvent* ev ){    QPainter painter(this);    // 去除畫筆    painter.setPen(Qt::NoPen);    // 設定反鋸齒    painter.setRenderHint(QPainter::Antialiasing);    //******************************************** 圓餅圖 *****************************************//    if(1)    {        // 頂層圓面        QRectF rect_top(10.0, 20.0, 280.0, 160.0);        // 底層圓面        QRectF rect_bottom(10.0, 60.0, 280.0, 160.0);        // 中間矩形        QRectF rect_midd(10.0, 100.0, 280.0, 40.0);        // 扇形起始角度        int startAngle = 230 * 16;        // 扇形覆蓋範圍        int spanAngle = 60 * 16;        painter.setBrush(QColor(97,35,35,255));        // 繪製底層圓面        painter.drawEllipse(rect_bottom);        // 繪製中間矩形        painter.drawRect(rect_midd);        painter.setBrush(QColor(Qt::darkYellow));        // 繪製底層扇形        painter.drawPie(rect_bottom, startAngle, spanAngle);        // 扇形的弦與弧的交點        double pi = 3.1415926;        double dx1 = rect_top.width() * 0.5 * cos(230 * pi / 180);        double dy1 = rect_top.height() * 0.5 * sin(230 * pi / 180);        double dx2 = rect_top.width() * 0.5 * cos(290 * pi / 180);        double dy2 = rect_top.height() * 0.5 * sin(290 * pi / 180);        // 求交點的座標值        QPointF posBackCenter = QPointF(rect_top.center());        double dX1 = posBackCenter.x() + dx1 + 0.5;        double dY1 = posBackCenter.y() - dy1 + 0.5;        double dX2 = posBackCenter.x() + dx2 + 0.5;        double dY2 = posBackCenter.y() - dy2 + 0.5;        // 記錄交點        QPointF topLeft = QPointF(dX1, dY1);        QPointF bottomRight = QPointF(dX2, dY2) + QPointF(0,40);        QPointF bottomLeft = topLeft + QPointF(0,40);        painter.setBrush(QColor(Qt::darkYellow));        // 繪製串連扇形的地區        QPolygonF path;        path << topLeft << QPointF(dX2,dY2) << bottomRight << bottomLeft;        painter.drawPolygon(path);        // 繪製頂層圓面        painter.setBrush(QColor(156,56,56,255));        painter.drawEllipse(rect_top);        // 繪製頂層扇形        painter.setBrush(QColor(Qt::yellow));        painter.drawPie(rect_top, startAngle, spanAngle);    }    QWidget::paintEvent(ev);}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.