Displaying an image file with QImage
Dear my friends... I use SuSE 9.1 and Qt 3.2 . I am writing a database program with Qt. I have an image file named "1.png", I want this image file displayed in a Dialog Form. Anybody would be so generous to give me a very simple sample code how to display an image file into a Dialog Form with QImage? All I know only this step : QImage::QImage("images/1.png"); Please give me a very simple sample code. Thank you very much in advance. _______________________________ Do you Yahoo!? Declare Yourself - Register online to vote today! http://vote.yahoo.com
On Friday 17 September 2004 15:16, Prabu Subroto wrote:
Dear my friends...
I use SuSE 9.1 and Qt 3.2 . I am writing a database program with Qt.
I have an image file named "1.png", I want this image file displayed in a Dialog Form.
Anybody would be so generous to give me a very simple sample code how to display an image file into a Dialog Form with QImage?
All I know only this step : QImage::QImage("images/1.png");
Please give me a very simple sample code.
You can use QLabel, instead of giving it a textual label, you give it an pixmap. QLabel *lb = new QLabel(this); lb->setPixmap("images/1.png"); Insert the QLabel into your dialog as usual. best, Jeroen
On Friday 17 September 2004 15:16, Prabu Subroto wrote:
I have an image file named "1.png", I want this image file displayed in a Dialog Form.
Anybody would be so generous to give me a very simple sample code how to display an image file into a Dialog Form with QImage?
All I know only this step : QImage::QImage("images/1.png");
QImage is almost always the wrong choice. Use a QLabel with a QPixmap in it.
QImage is for doing heavy image processing, not for simple displaying.
CU
--
Stefan Hundhammer
Create a QWidget The use the setPaletteBackgroundPixmap() to set it's background image (pixmap) to your file. QWidget* wig = new QWidget(this); wig->setPaletteBackgroundPixmap(QPixmap::QPixmap(QImage::QImage("images/1.png"))); wig->show(); B-) On Friday 17 September 2004 07:16 am, Prabu Subroto wrote:
Dear my friends...
I use SuSE 9.1 and Qt 3.2 . I am writing a database program with Qt.
I have an image file named "1.png", I want this image file displayed in a Dialog Form.
Anybody would be so generous to give me a very simple sample code how to display an image file into a Dialog Form with QImage?
All I know only this step : QImage::QImage("images/1.png");
Please give me a very simple sample code.
Thank you very much in advance.
_______________________________ Do you Yahoo!? Declare Yourself - Register online to vote today! http://vote.yahoo.com
Hallo Jeroen.
Firstly, thank you for your answer.
I did like this in
depanForm.ui.h :
#include
On Friday 17 September 2004 15:16, Prabu Subroto wrote:
Dear my friends...
I use SuSE 9.1 and Qt 3.2 . I am writing a database program with Qt.
I have an image file named "1.png", I want this image file displayed in a Dialog Form.
Anybody would be so generous to give me a very simple sample code how to display an image file into a Dialog Form with QImage?
All I know only this step : QImage::QImage("images/1.png");
Please give me a very simple sample code.
You can use QLabel, instead of giving it a textual label, you give it an pixmap.
QLabel *lb = new QLabel(this); lb->setPixmap("images/1.png");
Insert the QLabel into your dialog as usual.
best, Jeroen
-- To unsubscribe, email: suse-programming-e-unsubscribe@suse.com For additional commands, email: suse-programming-e-help@suse.com Archives can be found at: http://lists.suse.com/archive/suse-programming-e
_______________________________ Do you Yahoo!? Declare Yourself - Register online to vote today! http://vote.yahoo.com
On Friday 17 September 2004 15:51, Prabu Subroto wrote:
Hallo Jeroen.
Firstly, thank you for your answer.
I did like this in depanForm.ui.h :
#include
#include void depanForm::init() { QLabel * lb = new QLabel(this); lb->setPixmap("images/1.png"); }
Oops, lb->setPixmap(QPixmap("images/1.png")); see the QPixmap docs for more info. best, Jeroen
make sure the compiler knows what you are doing.
You need to include qlabel.h.
#include
Hallo Jeroen.
Firstly, thank you for your answer.
I did like this in depanForm.ui.h :
#include
#include void depanForm::init() { QLabel * lb = new QLabel(this); lb->setPixmap("images/1.png"); }
As I compiled this simple code (as my first try), I get this error message : patrixlinux@patrix:~/arsip/proyek/qt/10> make g++ -c -pipe -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -Wall -fPIC -Wall -W -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -Wall -fPIC -DQT_NO_DEBUG -DQT_SHARED -DQT_TABLET_SUPPORT -I/usr/lib/qt3/mkspecs/default -I. -I. -I/usr/include -I/usr/lib/qt3/include -o depanform.o depanform.cpp In file included from depanform.cpp:19: depanform.ui.h: In member function `virtual void depanForm::init()': depanform.ui.h:15: error: no matching function for call to `QLabel::setPixmap(const char[13])' /usr/lib/qt3/include/qlabel.h:104: error: candidates are: virtual void QLabel::setPixmap(const QPixmap&) make: *** [depanform.o] Error 1 patrixlinux@patrix:~/arsip/proyek/qt/10>
Why does it happen?
Please tell me.
Thank you very much in advance.
Newbie in Qt, Prabu.
--- Jeroen Wijnhout
wrote: On Friday 17 September 2004 15:16, Prabu Subroto
wrote:
Dear my friends...
I use SuSE 9.1 and Qt 3.2 . I am writing a
database
program with Qt.
I have an image file named "1.png", I want this
image
file displayed in a Dialog Form.
Anybody would be so generous to give me a very
simple
sample code how to display an image file into a
Dialog
Form with QImage?
All I know only this step : QImage::QImage("images/1.png");
Please give me a very simple sample code.
You can use QLabel, instead of giving it a textual label, you give it an pixmap.
QLabel *lb = new QLabel(this); lb->setPixmap("images/1.png");
Insert the QLabel into your dialog as usual.
best, Jeroen
-- To unsubscribe, email: suse-programming-e-unsubscribe@suse.com For additional commands, email: suse-programming-e-help@suse.com Archives can be found at: http://lists.suse.com/archive/suse-programming-e
_______________________________ Do you Yahoo!? Declare Yourself - Register online to vote today! http://vote.yahoo.com
oops,
maybe
Hallo Jeroen.
Firstly, thank you for your answer.
I did like this in depanForm.ui.h :
#include
#include void depanForm::init() { QLabel * lb = new QLabel(this); lb->setPixmap("images/1.png"); }
As I compiled this simple code (as my first try), I get this error message : patrixlinux@patrix:~/arsip/proyek/qt/10> make g++ -c -pipe -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -Wall -fPIC -Wall -W -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -Wall -fPIC -DQT_NO_DEBUG -DQT_SHARED -DQT_TABLET_SUPPORT -I/usr/lib/qt3/mkspecs/default -I. -I. -I/usr/include -I/usr/lib/qt3/include -o depanform.o depanform.cpp In file included from depanform.cpp:19: depanform.ui.h: In member function `virtual void depanForm::init()': depanform.ui.h:15: error: no matching function for call to `QLabel::setPixmap(const char[13])' /usr/lib/qt3/include/qlabel.h:104: error: candidates are: virtual void QLabel::setPixmap(const QPixmap&) make: *** [depanform.o] Error 1 patrixlinux@patrix:~/arsip/proyek/qt/10>
Why does it happen?
Please tell me.
Thank you very much in advance.
Newbie in Qt, Prabu.
--- Jeroen Wijnhout
wrote: On Friday 17 September 2004 15:16, Prabu Subroto
wrote:
Dear my friends...
I use SuSE 9.1 and Qt 3.2 . I am writing a
database
program with Qt.
I have an image file named "1.png", I want this
image
file displayed in a Dialog Form.
Anybody would be so generous to give me a very
simple
sample code how to display an image file into a
Dialog
Form with QImage?
All I know only this step : QImage::QImage("images/1.png");
Please give me a very simple sample code.
You can use QLabel, instead of giving it a textual label, you give it an pixmap.
QLabel *lb = new QLabel(this); lb->setPixmap("images/1.png");
Insert the QLabel into your dialog as usual.
best, Jeroen
-- To unsubscribe, email: suse-programming-e-unsubscribe@suse.com For additional commands, email: suse-programming-e-help@suse.com Archives can be found at: http://lists.suse.com/archive/suse-programming-e
_______________________________ Do you Yahoo!? Declare Yourself - Register online to vote today! http://vote.yahoo.com
On Friday 17 September 2004 15:46, Brad Bourn wrote:
Create a QWidget The use the setPaletteBackgroundPixmap() to set it's background image (pixmap) to your file.
QWidget* wig = new QWidget(this); wig->setPaletteBackgroundPixmap(QPixmap::QPixmap(QImage::QImage("images/1.p ng"))); wig->show();
That approach has drawbacks: If the widget's size is larger or smaller than
the pixmap's size, the pixmap is replicated (tiled) or cut off. That might
even be desired in some cases, but in general it is not.
The advantage is that this kind of pixmap is repainted automatically by the X
server, so that is really fast - the pixmap appears first on the screen, even
before widget boundaries are rendered.
CU
--
Stefan Hundhammer
You can also use transparencies, and you can scale the image to fit the widget. You can also move around, show & hide, treat as top level widget, etc. B-) On Friday 17 September 2004 08:32 am, Stefan Hundhammer wrote:
On Friday 17 September 2004 15:46, Brad Bourn wrote:
Create a QWidget The use the setPaletteBackgroundPixmap() to set it's background image (pixmap) to your file.
QWidget* wig = new QWidget(this); wig->setPaletteBackgroundPixmap(QPixmap::QPixmap(QImage::QImage("images/1 .p ng"))); wig->show();
That approach has drawbacks: If the widget's size is larger or smaller than the pixmap's size, the pixmap is replicated (tiled) or cut off. That might even be desired in some cases, but in general it is not.
The advantage is that this kind of pixmap is repainted automatically by the X server, so that is really fast - the pixmap appears first on the screen, even before widget boundaries are rendered.
CU -- Stefan Hundhammer
Penguin by conviction. YaST2 Development SuSE Linux AG Nuernberg, Germany
participants (4)
-
Brad Bourn
-
Jeroen Wijnhout
-
Prabu Subroto
-
Stefan Hundhammer