无法显示内部图像 [英] unable to display inner image

查看:86
本文介绍了无法显示内部图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在QT Creator 5.5中的QLabel中显示和旋转另一个图像中的图像。但是,我无法这样做。该项目采用UI格式。



lblVehSpd是来自交互式UI的Qlabel。



以下是代码:



在头文件中emu.h:

I'm trying to display and rotate an image within another image in the QLabel in QT Creator 5.5. However, I was unable to do so. The project was in a UI form format.

"lblVehSpd" is a Qlabel from the interactive UI.

the following are the codes:

In header file emu.h:

#include <QMainWindow>
#include <QApplication>
#include "PCANLight.h"
#include "Elements.h"
#include "iostream.h"
#include <QTextStream>
#include <QTimer>
#include <QStyleFactory>

#include <QImage>
#include <QPainter>
#include <QTransform>
#include <QPainterPath>
#include <QPixmap>
#include <QLabel>

#include <QStylePainter>

namespace Ui {
class Emu;
}



class Emu : public QMainWindow
{
    Q_OBJECT



public:
    explicit Emu(QWidget *parent = 0);
    ~Emu();
    PCANLight pcan;
    Elements e;
    void DrawBase(QPainter *painter);
    void DrawNeedle(QPainter *painter);

private slots:
   void UpdateCompass();
private:
    Ui::Emu *ui;
    void SpeedOMeter(QWidget *parent);
    void paintEvent(QPaintEvent *ev);
    QTimer *CompassTime;
};





在cpp文件中emu.cpp:





In cpp file emu.cpp:

Emu::Emu(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Emu)
{
 SpeedOMeter(this);
}

void Emu::SpeedOMeter(QWidget *parent)
{
    QImage BaseImage(":/speedometer.png");
    ui->lblVehSpd->setPixmap(QPixmap::fromImage(BaseImage));
    CompassTime = new QTimer(this);
    connect(CompassTime, SIGNAL(timeout()), this, SLOT(UpdateCompass()));
    CompassTime->start(1000);

}

void Emu::paintEvent(QPaintEvent *ev)
{
    QPainter p(this);
    p.setRenderHint(QPainter::Antialiasing, true);

    p.save();
    p.translate(400, 303);
    DrawBase(&p);;
    p.restore();


    p.save();
    p.translate(ui->lblVehSpd->width() + 68, ui->lblVehSpd->height()+68);
    p.rotate(90.0);
    DrawNeedle(&p);;
    p.restore();

}

void Emu::DrawBase(QPainter *painter)
{
    QPixmap Base(":/speedometer.png");
    painter->drawPixmap(0,0,400,303, Base);
}

void Emu::DrawNeedle(QPainter *painter)
{
    QPixmap Needle(":/needle.png");
    painter->drawPixmap(200,152,ui->lblVehSpd->width(),ui->lblVehSpd->height(), Needle);
}

void Emu::UpdateCompass()
{
    update();
}



Emu::~Emu()
{
    delete ui;
}

推荐答案

首先,您应该只加载一次图片,最好是作为Emu班级的成员。



由于坐标问题,图纸可能无效。尽量只在大海捞针; - )
At first you should load the pictures only once, best as members of your Emu class.

The drawing may not work because of coordinate issues. Try to only "draw the needle in your haystack" ;-)


这篇关于无法显示内部图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆