QPainter does not show up the image file
Dear my friends...
I am using SuSE 9.1 and Qt 3.2 .
I try this simple code:
#include
On 20 Sep 2004 at 10:46, Prabu Subroto wrote:
Date sent: Mon, 20 Sep 2004 10:46:48 -0700 (PDT)
From: Prabu Subroto
Dear my friends...
I am using SuSE 9.1 and Qt 3.2 .
I try this simple code: #include
#include void pixForm::init(QPainter * p) { p->drawPixmap( 0,0, QPixmap("images/iamlagiajan.jpg"),0,0,100,100); }
No problem in compiling. But if I run the compiled code, no picture showed up in the dialog form.
Where is my mistake?
Please tell me.
Thank you very much in advance.
Try turning it into a .png file (and don't forget to run qmake). Qt doesn't support .jpg out of the box... alan -- http://www.ibgames.net/alan Registered Linux user #6822 http://counter.li.org Winding Down - Weekly Tech Newsletter - subscribe at http://www.ibgames.net/alan/winding/mailing.html
Dear Alan...
Firstly, thank you very much for your answer.
I converted the image into png format with gimp 2.0 .
I did the same like this:
#include
On 20 Sep 2004 at 10:46, Prabu Subroto wrote:
Date sent: Mon, 20 Sep 2004 10:46:48 -0700 (PDT) From: Prabu Subroto
To: suse-programming-e@suse.com Subject: [suse-programming-e] QPainter does not show up the image file Dear my friends...
I am using SuSE 9.1 and Qt 3.2 .
I try this simple code: #include
#include void pixForm::init(QPainter * p) { p->drawPixmap( 0,0, QPixmap("images/iamlagiajan.jpg"),0,0,100,100); }
No problem in compiling. But if I run the compiled code, no picture showed up in the dialog form.
Where is my mistake?
Please tell me.
Thank you very much in advance.
Try turning it into a .png file (and don't forget to run qmake). Qt doesn't support .jpg out of the box...
alan -- http://www.ibgames.net/alan Registered Linux user #6822 http://counter.li.org Winding Down - Weekly Tech Newsletter - subscribe at http://www.ibgames.net/alan/winding/mailing.html
-- 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 Monday 20 September 2004 19:46, Prabu Subroto wrote:
void pixForm::init(QPainter * p) { p->drawPixmap( 0,0, QPixmap("images/iamlagiajan.jpg"),0,0,100,100); }
No problem in compiling. But if I run the compiled code, no picture showed up in the dialog form.
Where is my mistake?
You need to do that in a paint event, not at widget initialzation.
You might want to read the first few chapters of a book about Xlib
(e.g. http://www.amazon.com/exec/obidos/tg/detail/-/1565920023/ ) to learn
why.
CU
--
Stefan Hundhammer
Uffhh....
OK, I am going to buy the book.
but at this moment, please help me to solve my
problem.
I have not understood how should I use QPaintEvent.
All of the example code show this function in this
form " void pixForm::paintEvent( QPaintEvent * event)
".
Since I just want to make a try with "init()"
(constructor) I don't understand how should the
QPaintEvent implemented in my case.
I just want if my program executed than the pixForm
form appear, executes the constructor ( init() ), and
finally the image file showed up in the dialog form
(pixForm) .
Please give me a very short example code, please...
the example from trolltech is too complicated for me
at this time.
what does the QPaintEvent have to do with QPainter? I
meant the relationship. I know from my book that
QPaintEvent is a trigger but why I can not use init()
to start the image file to be showed up.
Thank you very much in advance.
====
#include
On Monday 20 September 2004 19:46, Prabu Subroto wrote:
void pixForm::init(QPainter * p) { p->drawPixmap( 0,0, QPixmap("images/iamlagiajan.jpg"),0,0,100,100); }
No problem in compiling. But if I run the compiled code, no picture showed up in the dialog form.
Where is my mistake?
You need to do that in a paint event, not at widget initialzation. You might want to read the first few chapters of a book about Xlib (e.g.
http://www.amazon.com/exec/obidos/tg/detail/-/1565920023/
) to learn why.
CU -- Stefan Hundhammer
Penguin by conviction. YaST2 Development SuSE Linux AG Nuernberg, Germany -- 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!? Take Yahoo! Mail with you! Get it on your mobile phone. http://mobile.yahoo.com/maildemo
On Tuesday 21 September 2004 15:46, Prabu Subroto wrote:
I have not understood how should I use QPaintEvent. All of the example code show this function in this form " void pixForm::paintEvent( QPaintEvent * event) ".
Since I just want to make a try with "init()" (constructor) I don't understand how should the QPaintEvent implemented in my case.
I just want if my program executed than the pixForm form appear, executes the constructor ( init() ), and finally the image file showed up in the dialog form (pixForm) .
X doesn't work this way (come to think of it, neither does Win32). You don't actively begin painting on the screen, the windowing system tells your application when to do that - by sending an event. In X11 lingo this is called an "expose event" - which means that parts of your application's window (or all of it) are "exposed", i.e. either uncovered from windows that had been obscuring it, or simply displayed for the first time. In Qt this is mapped directly to the paintEvent() - a virtual function every QWidget has. Normally, you don't have to care about this, but if you want to do low-level drawing, this is your entry point. For your purposes (just displaying PNG or JPG graphics) you could also have used a QLabel with a QPixmap in it - I had suggested that earlier in this thread. It's basically like this: QLabel * imageViewer = new QLabel( parent ); QPixmap * pixmap = new QPixmap( "/wherever/mypixmap.png" ); imageViewer->setPixmap( pixmap ); But of course you can also derive your own custom widget class and do that yourself - by overwriting the paintEvent() virtual function and doing your own drawing there. Of course, you also have to take care of resizing your widget according to the pixmap's size (something QLabel also takes care of automatically).
Please give me a very short example code, please... the example from trolltech is too complicated for me at this time.
Too complicated?! http://doc.trolltech.com/3.3/showimg-example.html#x1260 void ImageViewer::paintEvent( QPaintEvent *e ) { if ( pm.size() != QSize( 0, 0 ) ) { // is an image loaded? QPainter painter(this); painter.setClipRect(e->rect()); painter.drawPixmap(0, menubar->heightForWidth( width() ), pmScaled); } } It doesn't get very much easier than this...
what does the QPaintEvent have to do with QPainter? I meant the relationship.
paintEvent() typically uses a QPainter to do the drawing.
I know from my book that QPaintEvent is a trigger but why I can not use init() to start the image file to be showed up.
X clients (applications) are not supposed to initiate drawing. They are
supposed to do that upon receiving an expose event. Since the X protocol is a
pretty complex client-server architecture, you might be lucky if you violate
that convention, and sometimes it might even work out and your image might be
displayed, but you might as well be not so lucky. I'd rather not rely on my
luck too much in programming. ;-)
--
Stefan Hundhammer
participants (3)
-
alan@ibgames.com
-
Prabu Subroto
-
Stefan Hundhammer