PDA

View Full Version : QImange help loading image



thomasLen
8th August 2011, 03:35
I'm trying to load a image in qt4 windows and I can't get it to work

thanks for the help


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
im = new QPixmap;
im->load ("im04.jpg");
}

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

void MainWindow::paintEvent (QPaintEvent *){
QPainter qpainter (this);
qpainter.drawPixmap (0, 0, *im);
}
/////.h
class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
protected:
QPixmap *im;
void paintEvent (QPaintEvent *);
private:
Ui::MainWindow *ui;

};

Lykurg
8th August 2011, 07:40
Does it work with a png image? If so, you forgot to "include" the jpeg plugin or your path to the image is wrong.

Dong Back Kim
10th August 2011, 01:11
Whenever I load images into GUI, I always register them in the gui widget by using QtDesigner and using QImage to show them in paintEvent and works fine for me at all time.

Regards,