QT自定义旋转控件

本文介绍如何在QT中创建一个自定义的旋转控件,通过代码实现控件的旋转功能,并提供了调用方法的说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

代码如下:

#pragma once

#include <QLabel>

class comRotateLabel : public QLabel
{
	Q_OBJECT

public:
	comRotateLabel(QWidget *parent);
	~comRotateLabel();

	void SetImage(QImage * image);
	void SetImage(QString &imagePath);
	void SetRotate(int rotate);

protected:
	void paintEvent(QPaintEvent *e);

private:
	QImage m_image;
	int m_rotate;
};
#include <QPainter>

#include "comRotateLabel.h"

comRotateLabel::comRotateLabel(QWidget *parent)
	: QLabel(parent)
	, m_rotate(0)
{
}

comRotateLabel::~comRotateLabel()
{
}

void comRotateLabel::SetImage(QImage * image)
{
	m_image = *image;
}

void comRotateLabel::SetImage(QString &imagePath)
{
	m_image.load(imagePath);
}

void comRotateLabel::SetRotate(int rotate)
{
	m_rotate = rotate;
}

void comRotateLabel::paintEvent(QPaintEvent *e)
{
	QPainter painter(this);
	painter.setPen(Qt::NoPen);
	painter.setBrush(Qt::NoBrush);
	painter.setRenderH
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值