gpt4 book ai didi

image - 无法让图像在 Qt 的中心旋转

转载 作者:行者123 更新时间:2023-12-04 18:20:39 25 4
gpt4 key购买 nike

我正在尝试在 QLabel Widge 内旋转 89x89 图像。

#include "header.h"

disc::disc(QWidget *Parent) : QWidget(Parent)
{
orig_pixmap = new QPixmap();
rotate = new QLabel(this);
showDegrees = new QLabel(this);

orig_pixmap->load("pic.png");
degrees = 0;

rotate->resize(89,89);
rotate->move(100,10);
rotate->setStyleSheet("QLabel{background-color:red;}");

showDegrees->resize(100,100);
showDegrees->move(400,0);
}

void disc::rotate_disc()
{
QString string;
degrees++;
if(degrees == 360) degrees = 0;

QTransform rotate_disc;

rotate_disc.translate( (orig_pixmap->width()-rotate->width())/2 , (orig_pixmap->width()-rotate->height())/2);
rotate_disc.rotate(degrees,Qt::ZAxis);

QPixmap pixmap;
//pixmap = orig_disc->scaled(89,89,Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
pixmap = orig_pixmap->transformed(rotate_disc,Qt::SmoothTransformation);
rotate->setPixmap(pixmap);

string.append("Degrees: " + QString::number(degrees) + "*");
showDegrees->setText(string);
}

即使它旋转。图像的一半在 QLabel 之外滚动,因此那一侧不可见。我怎样才能使它在图像中心的原点(0,0)处中心旋转。

这是文件
http://www65.zippyshare.com/v/85775455/file.html

如果你看它,你会发现图像就像向左弹跳一样。我怎样才能让它在黑色区域内旋转。

我每 10 毫秒为 rotate_disc() 函数设置一个信号超时。我正在使用它来深入学习 Qt。

谢谢你!

最佳答案

我已经这样做了......

//Move windows's coordinate system to center.
QTransform transform_centerOfWindow( 1, 0, 0, 1, width()/2, height()/2 );

//Rotate coordinate system.
transform_centerOfWindow.rotate( m_LoadingDisk_degrees );

//Draw image with offset to center of image.
QPainter painter( this );

//Transform coordinate system.
painter.setTransform( transform_centerOfWindow );

//Load image.

//Notice: As coordinate system is set at center of window, we have to center the image also... so the minus offset to come to center of image.
painter.drawPixmap( -loadingDisk.width()/2, -loadingDisk.height()/2, loadingDisk );

关于image - 无法让图像在 Qt 的中心旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10767587/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com