zoukankan      html  css  js  c++  java
  • Qt渐变染色

    Qt渐变染色

    ColorGradientTest1.pro

    #-------------------------------------------------
    #
    # Project created by QtCreator 2021-05-29T19:30:05
    #
    #-------------------------------------------------
    
    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = ColorGradientTest1
    TEMPLATE = app
    
    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which has been marked as deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    
    SOURCES += 
            main.cpp 
            mainwindow.cpp
    
    HEADERS += 
            mainwindow.h
    
    FORMS += 
            mainwindow.ui
    mainwindow.h
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QtGui/QPainter>
    
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
        void drawArea1();
    
    protected:
        void paintEvent(QPaintEvent *);
    
    private:
        Ui::MainWindow *ui;
    };
    
    #endif // MAINWINDOW_H
    mainwindow.cpp
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    
    
    void MainWindow::paintEvent(QPaintEvent *)
    {
        QPainter painter(this);
        // 反走样
        painter.setRenderHint(QPainter::Antialiasing, true);
    
        // 设置渐变色,设置起点、终点
        QLinearGradient linear(100, 100, 200, 100);
        linear.setColorAt(0, QColor(145, 218, 204));
        linear.setColorAt(1, QColor(47, 141, 237));
    
        // 设置显示模式
        linear.setSpread(QGradient::PadSpread);
    
        // 设置画笔颜色、宽度
        painter.setPen(QPen(QColor(255, 255, 255, 0), 1));
    
        // 设置画刷填充
        painter.setBrush(QBrush(linear));
    
        // 绘制矩形
        painter.drawRect(QRect(100, 100, 200, 100));
    
    }
    
    
    void MainWindow::drawArea1()
    {
    
    }
    
    
    //////////
    main.cpp
    #include "mainwindow.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
    
        return a.exec();
    }

    参考:https://www.cnblogs.com/ybqjymy/p/13571546.html

    https://blog.csdn.net/wzz953200463/article/details/100637732

    #################

    QQ 3087438119
  • 相关阅读:
    hdu1852 Beijing 2008
    hdu-2582 f(n)---找规律+素数筛法
    hdu-1452 Happy 2004---因子和+逆元
    LightOJ-1028 Trailing Zeroes (I)---因子数目
    hdu1215 七夕节---因子和
    因子和&&因子数
    hdu-1492 The number of divisors(约数) about Humble Numbers---因子数公式
    hdu-2136 Largest prime factor---巧用素数筛法
    欧拉函数
    BZOJ4418: [Shoi2013]扇形面积并
  • 原文地址:https://www.cnblogs.com/herd/p/14826185.html
Copyright © 2011-2022 走看看