QPIXMAP图像未显示

QPixmap Image doesnt appear

本文关键字:显示 图像 QPIXMAP      更新时间:2023-10-16

im新的QT和IM在其中制作游戏。我想显示图标,但是在将一些代码放置后,我找不到任何地方。我很困惑,因为我没有任何错误,所以我很确定我没有添加一些东西。帮助。

战斗。H文件

#ifndef COMBAT
#define COMBAT
#include <QImage>
#include <QGraphicsPixmapItem>
class Combat: public QGraphicsPixmapItem{
public:
// constructors
//Combat(QPixmap *parent=NULL);
Combat(const QString x);
// setters/getters
void getOwner(QString x);
private:
QString owner;
};

战斗.cpp

#include "Combat.h"
#include <QGraphicsScene>

Combat::Combat(const QString x){
     // draw graphics
     setPixmap(QPixmap(x));
}
void Combat::getOwner(QString x){
     owner = x;
}
#endif // COMBAT

interface.h

#ifndef INTERFACE
#define INTERFACE
#include <QList>
#include "Hex.h"
#include "Combat.h"
class Interface{
public:
    // constructors
    Interface();
    // getters/setters
    QList<Hex*> getHexes();
    void getOwner(int x);
    // public methods
    void placeHexes();
    void placeCombat();

private:
     void createHexColumn(int x, int y, int numOfRows);
     QList<Hex*> hexes;
     void createCombatIcon(int x, int y, QString z);
     int owner;
};
#endif // INTERFACE

interface.cpp

#include "Interface.h"
#include "Game.h"
extern Game* game;

Interface::Interface(){
}
QList<Hex *> Interface::getHexes(){
    return hexes;
}
void Interface::placeHexes(){
     createHexColumn(100,100,6);
}
void Interface::placeCombat()
{
     createCombatIcon(100,100,":/grafika/atak_magiczny.png");
}
void Interface::createCombatIcon(int x, int y, QString z)
{
    Combat* icon = new Combat(z);
    icon->getOwner("player1");
    icon->setPos(x,y);
    game->scene->addItem(icon);
}

我不确定在哪里缺少的东西

我通过在qt creator中添加我的图形来解决问题...