逛奔的蜗牛

我不聪明,但我会很努力

   ::  :: 新随笔 ::  ::  :: 管理 ::
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);  

void Widget::paintEvent(QPaintEvent *) {
    QPainter painter(this);
    painter.translate(width() / 2, height() / 2);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setPen(Qt::transparent);
    painter.fillRect(-width(), -height(), width() * 2, height() * 2, Qt::gray);

    int radius = 100;

    // 外边框
    QLinearGradient lg1(0, -radius, 0, radius);
    lg1.setColorAt(0, QColor(255, 255, 255));
    lg1.setColorAt(1, QColor(166, 166, 166));
    painter.setBrush(lg1);
    painter.drawEllipse(-radius, -radius, radius << 1, radius << 1);

    // 内边框
    radius -= 13;
    QLinearGradient lg2(0, -radius, 0, radius);
    lg2.setColorAt(0, QColor(155, 155, 155));
    lg2.setColorAt(1, QColor(255, 255, 255));
    painter.setBrush(lg2);
    painter.drawEllipse(-radius, -radius, radius << 1, radius << 1);

    // 内部的圆
    radius -= 4;
    QRadialGradient rg(0, 0, radius);
    rg.setColorAt(0, QColor(245, 0, 0));
    rg.setColorAt(0.6, QColor(210, 0, 0));
    rg.setColorAt(1, QColor(140, 0, 0));
    painter.setBrush(rg);
    painter.drawEllipse(-radius, -radius, radius << 1, radius << 1);

    // 高光
    radius -= 3;
    QPainterPath path;
    path.addEllipse(-radius, -radius - 2, radius << 1, radius << 1);
    QPainterPath bigEllipse;

    radius *= 2;
    bigEllipse.addEllipse(-radius, -radius + 140, radius << 1, radius << 1);
    path -= bigEllipse;

    QLinearGradient lg3(0, -radius / 2, 0, 0);
    lg3.setColorAt(0, QColor(255, 255, 255, 220));
    lg3.setColorAt(1, QColor(255, 255, 255, 30));
    painter.setBrush(lg3);
    painter.drawPath(path);
}
posted on 2013-08-07 07:32 逛奔的蜗牛 阅读(3116) 评论(8)  编辑 收藏 引用 所属分类: Qt

评论

# re: Qt:绘制带高光的按钮[未登录] 2013-08-07 21:39 Tom
哇,这效果真炫!!  回复  更多评论
  

# re: Qt:绘制带高光的按钮 2013-08-27 11:15 Corey
highlight  回复  更多评论
  

# re: Qt:绘制带高光的按钮 2014-04-14 09:57 Friv 10
感谢码  回复  更多评论
  

# re: Qt:绘制带高光的按钮 2014-11-18 15:07 friv4school
哇,这效果真炫  回复  更多评论
  

# re: Qt:绘制带高光的按钮 2015-09-07 21:37 Kizi 10
它給了我很多有用的信息。非常感謝  回复  更多评论
  

# re: Qt:绘制带高光的按钮 2015-09-19 22:14 Friv 5
我很喜歡你的文章,我希望你將有很多項或更多  回复  更多评论
  

# re: Qt:绘制带高光的按钮 2016-01-05 15:09 Descargar Geometry Dash
Posts shared useful information and meaningful life, I'm glad to be reading this article and hope to soon learn the next article. thank you
  回复  更多评论
  

# re: Qt:绘制带高光的按钮 2016-01-05 15:15 Agar
This is an informative post review. I am so pleased to get this post article and nice information. I was looking forward to get such a post which is very helpful to us. A big thank for posting this article in this website. Keep it up.
  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理