zoukankan      html  css  js  c++  java
  • 用Qt绘制颜色渐变

    最近一直在看关于Qt开发库的东西,研究了一些基本使用,写了一个关于绘制颜色渐变的小程序,现在共同和大家分享

    声明一下,我是在linux下面用eclipse+CDT+qt开发的,感觉非常的好:-)


    下面是PaintWidget.h头文件的声明

     1#ifndef PAINTWIDGET_H_
     2#define PAINTWIDGET_H_
     3#include <QWidget>
     4#include <QPainter>
     5class PaintWidget:public QWidget
     6{
     7public:
     8    PaintWidget(QWidget *parent=0);
     9protected:
    10    void paintEvent(QPaintEvent *event);
    11}
    ;
    12
    13#endif /* PAINTWIDGET_H_ */

    PaintWidget.cpp文件

     1#include "PaintWidget.h"
     2
     3PaintWidget::PaintWidget(QWidget *parent):QWidget(parent)
     4{
     5
     6}

     7void PaintWidget::paintEvent(QPaintEvent */*event*/)
     8{
     9    QPainter pt(this);
    10    QColor color(0x00,0x00,0x00);
    11    for (int i=0;i<256;i++)
    12    {
    13        for (int j=0;j<256;j++)
    14        {
    15            color.setRgb(0xff,i,j,0xff);
    16            pt.setPen(color);
    17            pt.drawPoint(20+i,20+j);
    18            color.setRgb(i,0xff,j,0xff);
    19            pt.setPen(color);
    20            pt.drawPoint(296+i,20+j);
    21            color.setRgb(j,i,0xff,0xff);
    22            pt.setPen(color);
    23            pt.drawPoint(572+i,20+j);
    24        }

    25    }

    26}

     1/*
     2 *
     3 *
     4 *  Created on: 2008-11-13
     5 *      Author: zhanweisun
     6 */

     7#include <QApplication>
     8#include "PaintWidget.h"
     9int main(int argc, char *argv[])
    10{
    11    QApplication a(argc, argv);
    12    PaintWidget  widget;
    13    widget.show();
    14    return a.exec();
    15}

    16

  • 相关阅读:
    好好活,做有意义的事
    linux运维、架构之路-linux基础知识
    linux运维、架构之路-linux目录结构
    linux运维、架构之路-linux基础优化
    linux运维、架构之路-SSH远程管理服务
    linux运维、架构之路-实时同步方案
    linux运维、架构之路-nfs网络文件系统
    linux运维、架构之路-全网备份项目方案
    linux运维、架构之路-rsync
    编程题
  • 原文地址:https://www.cnblogs.com/sun_catboy/p/1333051.html
Copyright © 2011-2022 走看看