[Qt-interest] Painting outside QWidget::paintEvent() on MS Windows

varun singh mailthatmale at yahoo.co.in
Sat Jun 20 13:48:03 CEST 2009


hi,
thanx Alessandro for helping. 


Actually i tried the QPolyogn option, but the result was
same. I think the underlying system itself doesn't take into
account each and every mouse move event. 
Later, i refered to the Scribble example given with Qt
package. They have achieved the desired result by drawing
lines between two points for every
QWidget::mouseMoveEvent().
 
 
>I would not assume that there happens one paintEvent()
per >mouseMoveEvent.().
>
>update(), only schedules a paintEvent() call for
"later". If You have 
>your mouse events in a high frequency, multiple
scheduled paint events 
>may accumulate in the queue. And instead of executing
all of them, Qt 
>compresses them to one single paint event.
>
>Because of that, You should not only remember one singe
of coordinates. 
>Try using a QPolygon, which you add points to in the
mouse event and 
>which you use and clear when pointing. drawPoints()
takes a QPolygon as 
>parameter.
>
>Alessandro
> 
> 
> >--- On Sun, 14/6/09, varun singh <mailthatmale at yahoo.co.in>
> wrote:
> >
> > From: varun singh <mailthatmale at yahoo.co.in>
> > Subject: Re: Painting outside QWidget::paintEvent() on
> MS Windows
> > To: qt-interest at trolltech.com
> > Date: Sunday, 14 June, 2009, 8:28 PM
> > hi,
> > well thank you Srdjan my problem is at least
> partially
> > solved now.
> > 
> > A new issue:
> >  Well I'm trying to draw a line with
> > QWidget::mouseMoveEvent (just like it is done in a
> painting
> > software).
> > 
> > This is the code I've prepared:
> >
> *************************************************************
> > /* m_xCoord and m_yCoord are members of class MyWidget
> */
> > 
> > void MyWidget::mouseMoveEvent(QMouseEvent *event)
> > {
> >     m_xCoord = event->x();
> >     m_yCoord = event->y();  
> > /* Stores the x & y co-ordinates of 
> >  mouse position when the event occurs. */
> > 
> >     update(m_xCoord, m_yCoord, 5, 5);
> > /* Updates (Paints) the region specified by
> > co-ordinates given by this event */
> > }
> > 
> > void MyWidget::paintEvent(QPaintEvent *event)
> > {
> > 
> > /* paintEvent puts a point at a place specified
> > by x & y co-ordinates given by mouseMoveEvent().
> > */   
> > 
> >    QPainter painter(this);
> >    QPen p(Qt::red, 5, Qt::SolidLine,
> > Qt::SquareCap);
> >    painter.setPen(p);
> >    painter.begin(this);
> >    painter.setPen(p);
> >    painter.drawPoint(m_xCoord, m_yCoord);
> > }
> >
> *************************************************************
> > 
> > The issue is that it is not behaving the way it
> should.
> > Theoritically, it should put a point on every position
> that
> > I move over with the mouse clicked, but if I move over
> too
> > quickly, all the positions are not painted, thus
> forming
> > broken figures. 
> > 
> > I've also tried replaint() (instead of update()).
> > 
> > I wonder why it is happening and how can it be
> solved.
> > 
> > -Varun
> > 
> > > Hi,
> > > 
> > > 2009/6/13 varun singh <mailthatmale at yahoo.co.in>:
> > > >
> > > > hi,
> > > > I've started learning Qt on Microsoft
> Windows
> > > platform.
> > > >
> > > > Qt on Windows does not allow painting
> outside
> > > QWidget::paintEvent(). But I want to draw a
> pixel
> > specified
> > > by the click of the mouse (which could have been
> done
> > using
> > > QWidget::mousePressEvent(), had Qt allowed
> painting
> > outside
> > > > QWidget::paintEvent()).
> > > >
> > > > So, how can I do that?
> > > 
> > > Make your mouse click event cause a paint event.
> Then
> > paint
> > > in your
> > > paintEvent().
> > > 
> > > As in:
> > > 
> > > yourclass::mousePressEvent()
> > > {
> > >   mMessage = "Hello!";   
> > >    /* mMessage is a class member of type
> > > QString */
> > >   update();           
> > >         /* should cause a repaint */
> > > }
> > > 
> > > yourclass::paintEvent()
> > > {
> > >   qWarning(mMessage.toAscii());   /*
> > > mMessage has been modified in
> > > mousePressEvent() */
> > > }
> > > 
> > > Something like the above?
> > > 
> > > Srdjan
> > > 
> > > 



      Love Cricket? Check out live scores, photos, video highlights and more. Click here http://cricket.yahoo.com




More information about the Qt-interest-old mailing list