⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 paintarea.cpp

📁 Linux窗口程序设计__Qt4精彩实例分析上面的源代码第二部分.以循序渐进的方式进行源代码,包括Qt4下面的图形与图画对话框QMainWindow的源代码.
💻 CPP
字号:
#include "paintarea.h"
#include <math.h>

#define PI 3.1415926535

PaintArea::PaintArea(QWidget *parent)
{
    setPalette(QPalette(Qt::white));
    setAutoFillBackground(true);
    
    setMinimumSize(400,400);
    
    width = 1;
    penColor = Qt::red;
    brushColor = Qt::blue;
    rule = Qt::OddEvenFill;

}

void PaintArea::setFillRule(int index)
{
    rule = Qt::FillRule(index);
    update();
}

void PaintArea::setPenWidth(int w)
{
    width = w;
    update();
}

void PaintArea::setPenColor(QColor c)
{
    penColor = c;
    update();
}

void PaintArea::setBrushColor(QColor c)
{
    brushColor = c;
    update();
}

void PaintArea::paintEvent(QPaintEvent *)
{ 
    QPainter p(this);
    
    QPainterPath path;
    path.addRect(150,150,100,100);
    /*
    path.moveTo(150,150);
    path.lineTo(150,250);
    path.lineTo(250,250);
    path.lineTo(250,150);    
    path.closeSubpath();*/
    
    path.moveTo(100,100);
    path.cubicTo(300,100,200,200,300,300);
    path.cubicTo(100,300,200,200,100,100);
 
    path.setFillRule(rule);
    
    QPen pen;
    pen.setColor(penColor);
    pen.setWidth(width);
    p.setPen(pen);
    p.setBrush(QBrush(brushColor));
    
    p.drawPath(path);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -