Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, July 2007
more than one task in paintEvent ... is it possible??


Message 1 in thread

hi,

Can we do, more than one tasks in paintEvent??? for e.g.

paintFlag=0;

void Form1::paintEvent( QPaintEvent * )
{
 if(paintFlag==1)
    {
	//paint.setBackgroundMode(Qt::OpaqueMode );
	QPainter paint( this );
	paint.setBackgroundColor(Qt::white);
	paint.setPen(Qt::red);
		
paint.drawText(200,100,"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",-1,QPainter::LTR);
	paintFlag=0;
    }
    else
    {
	QPainter paint( this );
	paint.drawImage(0,0, img, 0,0,-1,-1,0 );             
	puts("AAAAAAAAAAAAAAA");
	paintFlag=1;
    }
}


and i am calling update() 2 times from focusInEvent of form.


image is showing first time correctly, but text is not coming on form....

Can u tell me what's wrong???


Thanks and Regards,
Niranjan.

--
 [ signature omitted ] 

Message 2 in thread

[snip]

> and i am calling update() 2 times from focusInEvent of form.
> 
> 
> image is showing first time correctly, but text is not coming on 
form....

Possibly the two generated paintEvents are merged into one event. Look at 
the docs at http://doc.trolltech.com/3.3/qwidget.html#update . 
You would have to use repaint() instead - which I would defenitly _NOT_ 
recommend you to do.
See http://doc.trolltech.com/3.3/qwidget.html#repaint for reasons why.
Actually I don't get why you are not just painting the image and the text 
one after the other. Why doing this strange paintFlag thing and trying to 
generate two paintEvents if you could do it just straight away???

Regards,

Malte

--
 [ signature omitted ] 

Message 3 in thread

hi,

Actually, i need to call paintEvent when want image on form on some event.
and on another event i want text on form. 

My two events are different. On first event i don't want any text, need to 
display only image. and On second event i need only text, not an image.



There is only one paintEvent function that will call using update on my first 
event, and call update on my second event. For this, i used flags..


Can u tell me what's  wrong????


Thanks and regards,
Niranjan

On Wednesday 18 July 2007 11:34, Malte Witt wrote:
> [snip]
>
> > and i am calling update() 2 times from focusInEvent of form.
> >
> >
> > image is showing first time correctly, but text is not coming on
>
> form....
>
> Possibly the two generated paintEvents are merged into one event. Look at
> the docs at http://doc.trolltech.com/3.3/qwidget.html#update .
> You would have to use repaint() instead - which I would defenitly _NOT_
> recommend you to do.
> See http://doc.trolltech.com/3.3/qwidget.html#repaint for reasons why.
> Actually I don't get why you are not just painting the image and the text
> one after the other. Why doing this strange paintFlag thing and trying to
> generate two paintEvents if you could do it just straight away???
>
> Regards,
>
> Malte
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body. List archive and information:
> http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Message 4 in thread

On Wednesday 18 July 2007 08:23, Niranjan wrote:
> Can u tell me what's  wrong????

You don't quite get the meaning of what a paint event is. Imagine there's 
nothing on the screen, and your widget is supposed to recreate its visual 
appearance on this empty screen area, that's what a paint event is. Before 
there's nothing, afterwards there's a visible widget. All you need to do in 
your widget is to store the widget state, so your paintEvent() code knows 
what to paint. In paintEvent() you cannot rely on anything that was painted 
before, in fact, you can rely on everything you painted before to have been 
erased.

Here's some good news. You don't have to follow this model if you don't want 
to. You can also create a QPixmap pixmap in your widget that you resize in 
resizeEvent like this:

    void resizeEvent(QResizeEvent *){
        pixmap.resize(size());
    }


Whenever you want to draw something, you draw into the pixmap, by creating a 
QPainter on the pixmap. Then you call update().

In your paintEvent() you do something like this:

    void paintEvent(QPaintEvent *e) {
        QPainter painter(this);
        painter.drawPixmap(0, 0, pixmap);
    }


Done, now you can fiddle around with the widget as if it was visual basic. 
Just watch out to not draw text on top of text, that won't look nice with 
anti-aliasing.


Good luck.

 Matthias

--
 [ signature omitted ] 

Message 5 in thread

Matthias Ettrich wrote:
> On Wednesday 18 July 2007 08:23, Niranjan wrote:
>> Can u tell me what's  wrong????
> 
> You don't quite get the meaning of what a paint event is. Imagine there's 
> nothing on the screen, and your widget is supposed to recreate its visual 
> appearance on this empty screen area, that's what a paint event is. Before 
> there's nothing, afterwards there's a visible widget. All you need to do in 
> your widget is to store the widget state, so your paintEvent() code knows 
> what to paint. In paintEvent() you cannot rely on anything that was painted 
> before, in fact, you can rely on everything you painted before to have been 
> erased.
> 
> Here's some good news. You don't have to follow this model if you don't want 
> to. You can also create a QPixmap pixmap in your widget that you resize in 
> resizeEvent like this:
> 
>     void resizeEvent(QResizeEvent *){
>         pixmap.resize(size());
>     }
> 
> 
> Whenever you want to draw something, you draw into the pixmap, by creating a 
> QPainter on the pixmap. Then you call update().
> 
> In your paintEvent() you do something like this:
> 
>     void paintEvent(QPaintEvent *e) {
>         QPainter painter(this);
>         painter.drawPixmap(0, 0, pixmap);
>     }
> 
> 
> Done, now you can fiddle around with the widget as if it was visual basic. 
> Just watch out to not draw text on top of text, that won't look nice with 
> anti-aliasing.
> 
> 
> Good luck.
> 
>  Matthias
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 

Niranjan,

Also note that if you use a single widget to draw multiple things, which is quite common, what you 
draw last visually overwrites everything on the same location of the widget.

That is if you do:

QPainter paint( this );	
paint.drawText(20,20,"Hello world!");
paint.drawImage(0,0, img );

and your image is sufficiently large to cover the text it will and therefore you won't see it. If 
you want to optionally draw things by using some sort of flag mechanism, and not more widgets, to 
draw an image and ontop draw optionally some text do :

QPainter paint( this );	

if ( imgIsNowVisible == true )
	paint.drawImage(0,0, img );

if ( textIsNowVisible == true )
	paint.drawText(20,20,"Hello world!");

You can have any number of optional components. Note that if you turn on painting of both text/img 
in the example above you will see both of them, in contrast if text was drawn first you most likely 
wouldn't see it.

hope this helps.
--stathis



Attachment:

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature