初学QT,在画线这里遇到问题,还请大神帮忙
#include "widget.h"#include "ui_widget.h"#include "debug.h"#include <QLine>#include <QLineF>void Str2Array(QByteArray Array,QString SendStr);
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget){ ui->setupUi(this); x=0; //在Widget类里定义的公共成员x,y,x1,y1 y=0; x1=100; y1=60;}
Widget::~Widget(){ delete ui;}
void Widget::on_Clear_clicked(){
IDE_TRACE_STR("Change");
x=x1; y=y1; x1 +=20; y1 +=30; update();}
void Widget::paintEvent(QPaintEvent *event) //重写paintEvent函数{ QPainter Paint(this); IDE_TRACE_STR("printer"); Paint.setPen(Qt::red); Paint.drawLine(x,y,x1,y1); //根据x,y,x1,y1 画直线}
我想实现的是运行之后,单击一个按钮就改变x,y,x1,y1的值,然后执行update(); 重新画直线,但是我测试发现,刚启动的时候能画一条直线,当按下按钮后就不显示任何直线了,为什么会这样