zoukankan      html  css  js  c++  java
  • 关于QT的QPainterPath::arcTo 详解

    这个函数文档的意思就是画弧,看了文档也不太明白,自己做了demo终于明白了意思

    移动到圆心,画180度半圆

    void TestArcTo::paintEvent(QPaintEvent *)
    {
    QPoint startPt(30, 30);
    QRect rect(startPt.x(), startPt.y(), 200, 200);
    QPainter p(this); 
    p.setRenderHint(QPainter::Antialiasing); //抗锯齿
    p.fillRect(rect, QColor(255, 255, 255));
    
    int arcR = rect.width()/2;
    int rectSize = rect.width();
    QPainterPath path;
    
    path.moveTo(startPt.x() + arcR, startPt.y() + arcR); //先移动到圆心
    path.arcTo(rect, 00.0f, 180.0f);      //以0度起点,逆时针画180度
    
    p.fillPath(path, QBrush(QColor(122, 122, 122)));
    }

    移动到圆心,以90度开始画180度半圆

    path.moveTo(startPt.x() + arcR, startPt.y() + arcR); //先移动到圆心
    path.arcTo(rect, 90.0f, 180.0f);      //以0度起点,逆时针画180度

    移动到圆心,以190度开始画180度半圆

    path.moveTo(startPt.x() + arcR, startPt.y() + arcR); //先移动到圆心
    path.arcTo(rect, 90.0f, 180.0f);      //以0度起点,逆时针画180度

     

    移动到某个点可以画弦月

    几个点组合

    矩形区圆角

    void TestArcTo::paintEvent(QPaintEvent *)
    {
        QRect rect(30, 30, 200, 200);
        QPainter p(this);  
        p.setRenderHint(QPainter::Antialiasing);
        p.fillRect(rect, QColor(255, 255, 0));
    
        int cornerSize = 50;       //调节圆角的大小
        int arcR = cornerSize/2;
        QPainterPath path;
        path.moveTo(rect.left() + arcR, rect.top());
        path.arcTo(rect.left(), rect.top(), cornerSize, cornerSize, 90.0f, 90.0f);
    
        path.lineTo(rect.left(), rect.bottom() - arcR);
        path.arcTo(rect.left(), rect.bottom() - cornerSize, cornerSize, cornerSize, 180.0f, 90.0f);
    
        path.lineTo(rect.right() - arcR, rect.bottom());
        path.arcTo(rect.right() - cornerSize, rect.bottom() - cornerSize, cornerSize, cornerSize, 270.0f, 90.0f);
    
        path.lineTo(rect.right(), rect.top() + arcR);
        path.arcTo(rect.right() - cornerSize, rect.top(), cornerSize, cornerSize, 0.0f, 90.0f);
    
        p.fillPath(path, QBrush(QColor(122, 122, 122)));
    }

    底部和右边有黄色边框需要处理,这就需要+1, -1微调了。理解了arcTo函数,都不难处理。

    最方便的圆角方法

    void TestArcTo::paintEvent(QPaintEvent *)
    {
        QRect rect(30, 30, 200, 200);
        QPainter p(this);  
        p.setRenderHint(QPainter::Antialiasing);
        p.fillRect(rect, QColor(255, 255, 0));
    
        p.setPen(Qt::NoPen);
        p.setBrush(QColor(122, 122, 122));
        p.drawRoundedRect(rect, 20, 20);
    }

  • 相关阅读:
    笔记(二) C#sql语句
    [叩响C#之门]写给初学者:多线程系列(七)——互锁(Interlocked类)
    C# Async与Await的使用
    C#线程锁使用全功略
    一个C#的加锁解锁示例
    【分析】浅谈C#中Control的Invoke与BeginInvoke在主副线程中的执行顺序和区别(SamWang)
    Control.BeginInvoke()和delegate的BeginInvoke()的区别
    crm04 action操作 和 多级过滤
    VIM和sed 替换字符串方法
    解决Centos关闭You have new mail in /var/spool/mail/root提示(转)
  • 原文地址:https://www.cnblogs.com/yuzhould/p/9132493.html
Copyright © 2011-2022 走看看