• QT 气泡消息绘制


    bool QdsTextMessageControl::eventFilter(QObject *watched, QEvent *event)
    {
        if (watched == m_pFrameMessage)
        {
            if (event->type() == QEvent::Paint)
            {
                switch (m_TextMessageType)
                {
                case Me:
                {
                    QColor colorBg(11, 19, 39);

                    QPainter painter(m_pFrameMessage);
                    painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);//消锯齿
                    painter.setPen(Qt::NoPen);

                    QColor colorKuang(44, 116, 250);
                    painter.setBrush(QBrush(colorKuang));

                    //框加边
                    painter.drawRoundedRect(0, 0, m_pFrameMessage->width() - TriangleWidth, m_pFrameMessage->height(), 4, 4); 

                    //绘制框
                    painter.setBrush(QBrush(colorBg));
                    painter.drawRoundedRect(1, 1, m_pFrameMessage->width() - TriangleWidth - 2, m_pFrameMessage->height() - 2, 4, 4);//减1表示边大小

                    //三角的边
                    QPointF pointsBorder[3] = {
                        QPointF(m_pFrameMessage->width(), m_pFrameMessage->height() / 2),
                        QPointF(m_pFrameMessage->width() - TriangleWidth, m_pFrameMessage->height() / 2 - TriangleWidth),
                        QPointF(m_pFrameMessage->width() - TriangleWidth, m_pFrameMessage->height() / 2 + TriangleWidth),
                    };
                    QPen pen;
                    pen.setColor(colorKuang);
                    painter.setPen(pen);
                    painter.drawPolygon(pointsBorder, 3);

                    //三角内框
                    QPointF points[3] = {
                        QPointF(m_pFrameMessage->width()-1, m_pFrameMessage->height() / 2),
                        QPointF(m_pFrameMessage->width() - TriangleWidth - 1, m_pFrameMessage->height() / 2 - TriangleWidth),
                        QPointF(m_pFrameMessage->width() - TriangleWidth - 1, m_pFrameMessage->height() / 2 + TriangleWidth),
                    };
                    pen.setColor(colorBg);
                    painter.setPen(pen);
                    painter.drawPolygon(points, 3);
                    return false;
                }
                case Kefu:
                {
                    QColor colorBg(36, 36, 36);
                    QPainter painter(m_pFrameMessage);
                    painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);//消锯齿
                    painter.setPen(Qt::NoPen);
                    painter.setBrush(QBrush(colorBg));

                    //框加边
                    painter.drawRoundedRect(TriangleWidth, 0, m_pFrameMessage->width() - TriangleWidth, m_pFrameMessage->height(), 4, 4);

                    //三角
                    QPointF points[3] = {
                        QPointF(0, m_pFrameMessage->height() / 2),
                        QPointF(TriangleWidth, m_pFrameMessage->height() / 2 - TriangleWidth),
                        QPointF(TriangleWidth, m_pFrameMessage->height() / 2 + TriangleWidth),
                    };
                    QPen pen;
                    pen.setColor(colorBg);
                    painter.setPen(pen);
                    painter.drawPolygon(points, 3);
                    return false;
                }
                default:
                    break;
                }
            }
        }
        else
        {
            return false;
        }
    }

  • 相关阅读:
    漫谈测试成长之探索——测试排期
    R语言ggplot2和gganimate包可视化动态动画气泡图(Animated Bubble chart):使用gganimate包创建可视化gif动图
    Python推导式构建集合字典
    【ISO】Windows10系统ISO镜像怎么从微软官网下载?
    containerd的ctr tasks kill不起作用
    03 变量
    windows socket网络编程--事件选择模型
    uni-app——网络请求、数据缓存
    linux 查看CPU架构是AMD还是ARM
    docker安装
  • 原文地址:https://blog.csdn.net/soft_123456/article/details/126500479