.cpp
#include "widget.h"
#include "ui_widget.h"
#include <QPainter>
#include <QDebug>
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
ui->horizontalSlider->setMaximum(410);
ui->horizontalSlider->setMinimum(130);
connect(ui->horizontalSlider,SIGNAL(valueChanged(int)),this,SLOT(hSliderValueChangedSlot(int)));
}
Widget::~Widget()
{
delete ui;
}
void Widget::paintEvent(QPaintEvent *)
{
QPainter p (this);
p.translate( this->width()/2 , this->height() /2 );
p.drawPixmap(-200,-200,400,400,QPixmap(":/rs/Pan.png"));
p.rotate( ui->horizontalSlider->value() );
p.drawPixmap(-15,-15,150,30,QPixmap(":/rs/Point.png"));
}
void Widget::hSliderValueChangedSlot(int)
{
qDebug()<<__func__;
//通知,整个窗口重绘
this->update();
}
.h文章来源:https://www.toymoban.com/news/detail-804958.html
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
void paintEvent(QPaintEvent *);
public slots:
void hSliderValueChangedSlot(int);
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
文章来源地址https://www.toymoban.com/news/detail-804958.html
到了这里,关于QT 1.17的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!