[Qt-interest] QWidget::setCursor() and qApp->processEvents()

Frank Hemer frank at hemer.org
Thu Jul 29 16:48:41 CEST 2010


On Thursday 29 July 2010 16:13:37 Joshua Grauman wrote:
> Thanks!
>
> This indeed did the trick, but I must admit it is a bit baffling to me. I
> didn't think the cursor was drawn by Qt, but by the OS. That's why I
> didn't think of doing a repaint although I understand how the event system
> works. Indeed, my cursor is animated and it still animates smoothly while
> I am doing my calculations while the rest of my app is completely
> unresponsive... This seems to suggest that indeed the OS is drawing the
> cursor, but then I'm still confused as to why a repaint is necessary to
> change the cursor???

Well - repaint forces qt to immediatelly execute the call to the graphics 
engine. Still the cursor is drawn by the os - independant of your application 
process.
The difference is that update () will be executed during the next eventLoop 
cycle while repaint () is called immediatelly. Note that this might render 
your app unusable if used in a non-intended way ... 

Frank

> Josh
>
> > Josh:
> >
> >  Does some_widget_or_other->repaint() work for you?
> >
> >                     Atlant
> >
> > -----Original Message-----
> > From: qt-interest-bounces at trolltech.com
> > [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Josh Sent:
> > Wednesday, July 28, 2010 23:45 PM
> > To: qt-interest at trolltech.com
> > Subject: [Qt-interest] QWidget::setCursor() and qApp->processEvents()
> >
> > Hello all,
> >
> > Before I do some calculations in my program I want to set the cursor
> > using: viewport()->setCursor(Qt::WaitCursor);
> >
> > However, the cursor doesn't change because of the calculations. I don't
> > want to call qApp->processEvents() during the calculations because I
> > actually want the ui *not* to respond while the calculations are taking
> > place. So I was able to get the cursor to update BEFORE the calculations
> > as follows:
> >
> > qApp->processEvents();
> > qApp->processEvents();
> > viewport()->setCursor(Qt::WaitCursor);
> > for(int i=0; i<20; i++)
> >   qApp->processEvents();
> > do my calculations...
> >
> > This is obviously a hack. I needed to call processEvents 20 times for the
> > cursor to update. Any less and the cursor wouldn't update before my
> > calculations. I would assume that on different machines I might need
> > different number of calls to processEvents(), which is undesirable.
> > Anyone have any ideas on the correct way to do this?
> >
> > So in summary:
> > How can I make sure the cursor is changed before doing my calculations
> > when I don't want to call processEvents() during my calculations?
> >
> > Thanks!
> >
> > Josh
> > _______________________________________________
> > 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