#include "widget.h"
#include "ui_widget.h"
#include <QPainter>
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
ui->horizontalSlider->setMaximum(300);
ui->horizontalSlider->setMinimum(0);
connect(ui->horizontalSlider,SIGNAL(valueChanged(int)),this,SLOT(hSliderValueChangedSlot(int)));
}
Widget::~Widget()
{
delete ui;
}
void Widget::paintEvent(QPaintEvent *event)
{
double R = this->width()/3;
double r = this->width()/3;
QPainter p(this);
p.translate(this->width()/2, this->height()/2);
p.setBrush(brush);
p.drawPixmap(-R,-R, 2*R,2*R,QPixmap(":/rs/Pan.png"));
p.rodate(120);
p.rotate( ui->horizontalSlider->value() );//旋转
p.drawPixmap(-20,-25,r/1.2,r/6,QPixmap(":/rs/Point.png"));
}
void Widget::hSliderValueChangedSlot(int)
{
update();// 要求重绘
}
运行结果