[Qt-interest] repaint()
Konstantin Tokarev
annulen at yandex.ru
Tue Sep 21 15:08:45 CEST 2010
21.09.2010, 16:38, "phil prentice" <philp.cheer at talktalk.net>:
> 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??
Because you are wasting a lot of resources continuously calling QCoreApplication::processEvents();
Use QEventLoop to introduce pause in the cycle
Also I'd recommended you to use update() instead of repaint() in this case
--
Regards,
Konstantin
More information about the Qt-interest-old
mailing list