QT入门_QPainter基本绘图

这篇博客介绍了QT中的QPainter基本绘图操作,包括线条、填充、形状修改等,并展示了实验效果。同时,博主详细记录了在开发过程中遇到的三个错误:`vtable for PaintArea`、`PaintArea::PaintArea(Widget*)`匹配失败以及`Widget::~Widget()`的返回类型错误,给出了相应的解决方法和参考资料。通过这篇日志,读者可以了解到QT编程中可能遇到的问题及解决思路。
摘要由CSDN通过智能技术生成

实验效果,使用方法和功能

初始界面:
在这里插入图片描述
点击线条右边的修改
在这里插入图片描述
再修改填充,调整线宽

在这里插入图片描述
将形状改为RoundRect
在这里插入图片描述
附录:
文件一览:
在这里插入图片描述

代码

main.cpp

#include <QApplication>
#include <widget.h>
int main(int argc,char* argv[])
{
   
    QApplication a(argc,argv);
    Widget w;
    w.show();
    return a.exec();
}

widget.h

#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QComboBox>
#include <QFrame>
#include <QSpinBox>
#include <paintarea.h>
class Widget:public QWidget
{
   
    Q_OBJECT
public:
    explicit Widget(QWidget* parent = 0);
    ~Widget();
protected:
    QComboBox* shapeComboBox;
    QFrame* colorFrame;
    QFrame* brushColorFrame;
    QSpinBox* widthSpinBox;
    PaintArea* paintArea;
public slots:
    //修改形状槽函数
    void slotShape(int);
    //修改画笔槽函数
    void slotPenColor();
    //修改笔宽槽函数
    void slotPenWidth(int);
    //修改画刷槽函数
    void slotBrushColor();
};
#endif // WIDGET_H

widget.cpp

#include <Widget.h>
#include <QLabel>
#include <QComboBox>
#include <QPushButton>
#include <QSpinBox>
#include <paintarea.h>
#include <QColor>
#include <QColorDialog>

Widget::Widget(QWidget *parent): QWidget(parent)
{
   
    //设置主窗口大小
    this->resize(700,400);

    QLabel * SharpLabel = new QLabel("形状:",this);
    shapeComboBox = new QComboBox(this);
    SharpLabel->setGeometry(430,20,60,40);
    shapeComboBox->setGeometry(500,20,150,40);
    shapeComboBox->addItem("Line",PaintArea::Line);
    shapeComboBox->addItem("Rectangle",PaintArea::Rectangle);
    shapeComboBox->addItem("RoundRect",PaintArea::RoundRect)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值