[Qt-interest] repaint()

phil prentice philp.cheer at talktalk.net
Tue Sep 21 19:44:51 CEST 2010


Hi
  I eventually found out that repaint does not do anything unless I give it a 
rectangle to draw i.e.  
m_graph[i]->repaint(m_graph[i]->rect())

I kinda assumed that redraw would redraw everything, but obviously not??!!


I basically redraw as required my six graphs.  It looks promising, but I still 
may get a problem with flicker, although it does not look to bad on my 
machine which is not quick anyway...I will see when I am talking to the 
hardware. 

Thankyou very much for your help

Phil


On Tuesday 21 September 2010 16:06, phil prentice wrote:
> Hi Atlant
>   I really appreciate your help. This is probably where I am coming
> unstuck. Basically the application is talking to hardware inside my for
> loop.  I was then hoping that a redraw within the for loop would directly
> cause a repaint event which would ripple down to a widget which would then
> read (as part of its paintEvent) the new data generated from the hardware
> and update the screen.
>
>   This does not happen, so I am obviously missing something.
> I just naively thought that redraw() would force a draw for all widgets???
>
>   Its probably because QT does not actually think anything has changed???
>
>   At the moment my widget paintEvent() looks like this (Its only experiment
> mode). I am just trying to play around with data, to see what sort of
> flicker effect I might get.  My problem is that the paintEvent() is not
> being called when I call redraw???  I have six VIgraph objects. These
> objects get drawn at start, but not when I go into continuos mode; The
> repaint just does not call:-
>
> void VIgraph::paintEvent(QPaintEvent *event)
> {
>   qDebug("CALL");
>   static int frig[6];
>   static int p1[40] = { 0, 30, 5, 40, 30, 10, 40, 5, 47, 0,
>                         47, -10, 35, -20, 30, -30, 10, -45, 0, -42,
>                         -5, -50, -10, -40, -30, -30, -40, -10, -50, -5,
>                         -47, 10, -30, 20, -20, 25, -10, 30, 0, 30, };
>   static int p2[40] = { 5, 35, 10, 45, 35, 15, 45, 10, 30, 0,
>                         40, -15, 40, -25, 35, -35, 15, -50, 0, -47,
>                         -10, -55, -15, -45, -35, -35, -45, -15, -55, -10,
>                         -20, 15, -35, 25, -25, 30, -15, 35, 5, 35, };
>   QFrame::paintEvent(event);
>   QPainter painter(this);
>   painter.setWindow(-50, -50, 100, 100);
>   painter.drawLine(-50, 0, 50, 0);
>   painter.drawLine(0, -50, 0, 50);
>
>   int me = objectName().toInt();
>   QPoint pList1[20];
>   if(frig[me])
>   {
>     frig[me] = 0;
>     int j = 0;
>     for(int i = 0; i < 20; i++)
>     {
>       pList1[i].setX(p1[j++]);
>       pList1[i].setY(p1[j++]);
>     }
>   }
>   else
>   {
>     frig[me] = 1;
>     int j = 0;
>     for(int i = 0; i < 20; i++)
>     {
>       pList1[i].setX(p2[j++]);
>       pList1[i].setY(p2[j++]);
>     }
>   }
>   painter.drawPolyline(pList1, 20);
> }
>
>  On Tuesday 21 September 2010 13:09, you wrote:
> > Phil:
> >
> >   I'm unclear on where the "data ready to be redrawn"
> >   has any opportunity to be effective. That is, when
> >   you're within the for loop, Qt is asked to do the
> >   repaint() and has the opportunity to do the repaint
> >   (when you call processEvents()), but what has actually
> >   changed that will paint any differently than the last
> >   time the loop invoked the repaint?
> >
> >                          Atlant
> >
> > -----Original Message-----
> > From: qt-interest-bounces at trolltech.com
> > [mailto:qt-interest-bounces at trolltech.com] On Behalf Of phil prentice
> > Sent: Tuesday, September 21, 2010 08:39
> > To: qt-interest at trolltech.com
> > Subject: [Qt-interest] repaint()
> >
> > Hi everyone
> >
> >   I would be grateful for a little help using paintEvent().  I have an
> > application that has a "Continuous Button". I have implemented the slot
> > using the following basic code.
> > void VIwindow::continuousSlot()         // SLOT
> > {
> >   static bool running = false;
> >   if(m_continuousButton->text() == "Stop")
> >   {
> >     running = false;
> >     return;
> >   }
> >   else
> >   {
> >     running = true;
> >     m_continuousButton->setText("Stop");
> >     repaint();  // Force a direct update.   Works!!!
> >     for(;;)
> >     {
> >        // Update some widgets with data ready to be redrawn
> >       repaint();  // The widgets are not being drawn????
> >       // Check for stop being pressed.
> >       QCoreApplication::processEvents();
> >        if(!running)
> >          break;
> >     }
> >     m_continuousButton->setText("Continuous");
> >   }
> > }
> >
> > The mechanism works very well except the repaint in the for loop does not
> > do anything.  I know this is probably a very basic question, but why??
> >
> > Thankyou for your help
> >
> > Phil
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
> >
> > This e-mail and the information, including any attachments, it contains
> > are intended to be a confidential communication only to the person or
> > entity to whom it is addressed and may contain information that is
> > privileged. If the reader of this message is not the intended recipient,
> > you are hereby notified that any dissemination, distribution or copying
> > of this communication is strictly prohibited. If you have received this
> > communication in error, please immediately notify the sender and destroy
> > the original message.
> >
> > Thank you.
> >
> > Please consider the environment before printing this email.
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest



More information about the Qt-interest-old mailing list