QT實現視窗圓角

來源:互聯網
上載者:User
    //==========實現上邊角圓弧==========    setWindowFlags(Qt::FramelessWindowHint);    QBitmap bmp(this->size());    bmp.fill();    QPainter p(&bmp);//    p.setPen(Qt::NoPen);//    p.setBrush(Qt::black);    p.setRenderHint(QPainter::Antialiasing);    //消除鋸齒    //p.drawRoundedRect(bmp.rect(), 20, 20); //四個角都是圓弧    //只要上邊角圓弧    int arcR = 10;    //弧度    QRect rect = this->rect();    QPainterPath path;    //逆時針    path.moveTo(arcR, 0);    path.arcTo(0, 0, arcR * 2, arcR * 2, 90.0f, 90.0f);    path.lineTo(0, rect.height());    path.lineTo(rect.width(), rect.height());    path.lineTo(rect.width(), arcR);    path.arcTo(rect.width() - arcR * 2, 0, arcR * 2, arcR * 2, 0.0f, 90.0f);    path.lineTo(arcR, 0);    p.drawPath(path);    //p.fillPath(path, QBrush(Qt::Red)); //arm和windows平台沒有這行代碼將顯示一個透明的空空的框    setMask(bmp);    //==========實現上邊角圓弧==========

 可以放在表單的建構函式中,具體的代碼原理我也沒有詳細看,拿來主意,:-)。

原理應該是使用一個BITMAP來實現表單繪畫,圓角是使用path路徑來逐步畫出來的。

 

轉自:http://blog.csdn.net/fariel_zhang/article/details/6315463

一些畫圖原理可參考:http://blog.sina.com.cn/s/blog_83dddc170100s0u4.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.