[Qt-interest] Difficulty creating Pixmaps
Szalata, Zenon M.
zms at slac.stanford.edu
Sun Aug 28 05:14:31 CEST 2011
Thank you Jason,
That was exactly the problem. I added the other files to the .qrc file and that solved the problem.
Zen
From: Jason H [mailto:scorp1us at yahoo.com]
Sent: Saturday, August 27, 2011 5:08 PM
To: Szalata, Zenon M.; qt-interest at trolltech.com
Subject: Re: [Qt-interest] Difficulty creating Pixmaps
Are these images compiled in?
the : in the filenames makes me think that they are compiled in as resources.
Remove the colon?
________________________________
From: "Szalata, Zenon M." <zms at slac.stanford.edu>
To: "qt-interest at trolltech.com" <qt-interest at trolltech.com>
Sent: Saturday, August 27, 2011 7:44 PM
Subject: [Qt-interest] Difficulty creating Pixmaps
I hope that someone has time to read this lengthy note and help me with the following:
I am using QT 4.7.0 on RedHat Linux.
I have taken a few statements from the example qt/examples/painting/basicdrawing program
to create a simple test program, which I am using to learn how to display images from image files (jpeg and or png). One of the image files, qt-logo.png, came with the example “basicdrawing” program.
My test program displays correctly the image from qt-logo.png file. However, when I use a different file then no image is displayed. I have used image files that I have created with GIMP or converted jpeg files to png with GIMP, they do not seem to work. I have also taken the file
qt/examples/painting/imagecomposition/images/butterfly.png
and my test program does not work with it.
I have also taken the original qt-logo.png, converted it to qt-logo.jpg using GIMP. This jpg file does not work. I have then converted the qt-logo.jpg back to qtLogo.png using GIMP. This new png file does not work either. Also, this doubly converted png file is about 2.5 time the size of the original. I don’t understand why it is so much bigger than the original. I am attaching some of the image files.
The test program is constructed by inserting an object of the RenderArea in a main window.
Here is the source code for the RenderArea class:
#include <QtGui>
#include "renderarea.h"
RenderArea::RenderArea(QWidget *parent): QWidget(parent){
QString file1=":/images/qt-logo.png";
QString file2=":/images/nlctaSketch.png";
QString file3=":/images/21.png";
QString file4=":/images/qt-logo.jpg";
QString file5=":/images/button.png";
QString file6=":/images/21.jpg";
QString file7=":/images/place.jpg";
QString file8=":/images/butterfly.png";
pixmap1.load(file1);
image1.load(file7);
// pixmap1.fromImage( image1);
setBackgroundRole(QPalette::Base);
setAutoFillBackground(true);
QRect rect=this->geometry();
qDebug()<< "RenderArea:: rect = "<<rect;
qDebug()<<"RenderArea:: pixmap size="<<pixmap1.size();
}
QSize RenderArea::minimumSizeHint() const{ return QSize(100, 100);}
QSize RenderArea::sizeHint() const{ return QSize(400, 200);}
void RenderArea::paintEvent(QPaintEvent * /* event */){
QPainter painter(this);
painter.drawPixmap(0,0,pixmap1);
painter.setPen(palette().dark().color());
painter.setBrush(Qt::NoBrush);
painter.drawRect(QRect(0, 0, width() - 1, height() - 1));
}
Of all the files listed in the constructor only qt-logo.png gets painted in my test program. Now, all these can be used successfully in a QLabel. The size of the image which works is printed correctly when the program starts up. The size for all the other images, which do not work, is printed as (-1,-1). I could not find documentation which explains what that mean. It probably means that the Pixmap is empty.
#ifndef RENDERAREA_H
#define RENDERAREA_H
#include <QBrush>
#include <QPen>
#include <QPixmap>
#include <QWidget>
class RenderArea : public QWidget{
Q_OBJECT
public:
RenderArea(QWidget *parent = 0);
QSize minimumSizeHint() const;
QSize sizeHint() const;
protected:
void paintEvent(QPaintEvent*);
private:
QPixmap pixmap1;
QImage image1;
};
#endif
I am completely stuck on this, since I have no experience handling images in QT applications.
I will be grateful for any help, hints, etc.
Thanks,
Zen
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com<mailto:Qt-interest at qt.nokia.com>
http://lists.qt.nokia.com/mailman/listinfo/qt-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110827/67a8e16d/attachment.html
More information about the Qt-interest-old
mailing list