PDA

View Full Version : QWidget.show () is slow



rdf
13th September 2011, 14:05
Hi everyone,

I'm developing a Linux Qt (4.7.4) GUI application which can be shown/hidden using specific commands on a TCP socket. The base class is a QWidget, which then contains different labels, buttons, images, etc. There are more or less 30 elements.

My problem is that every time I call >show ()< on my main widget a black background immediately appears, but all the widgets and the real background (from a PNG image) comes after a certain delay (at least 0,5s on my desktop here). This every time I do a hide/show cycle.

How can I get rid of this delay? Or, at least, can I have all my interface coming out altogether, even if delayed, without the black "intermediate" background?

Thanks
Roberto

wysota
13th September 2011, 14:28
Are you using stylesheets for the backgrounds? Are the images being scaled when shown on widgets?

rdf
13th September 2011, 14:51
Are you using stylesheets for the backgrounds? Are the images being scaled when shown on widgets?

Yes, I'm using stylesheets on QLabel like mainly like this:
"QLabel { background-image: url(img.png) }"

But also on three labels like this, stretching:
"QLabel { border-width: 4px; border-image: url(img.png) 4 4 4 4 stretch stretch}"

Is this the bottleneck?

Thanks!
Roberto

wysota
13th September 2011, 15:17
Yes, this is the bottleneck. Every time the widget is shown, the image needs to be scaled. If it is large, scaling takes time. It's better to prescale the image to the size of the widget and then either set it using stylesheets or draw them manually from within the paint event (which will be more efficient).

rdf
13th September 2011, 15:33
Thank you wysota, that was it. I removed the picture stretching and it's already much better (especially from the second time it's shown). I'll try to avoid the stylesheets as this is a particular application that runs on a not-so-performing embedded PC with touch screen.

Roberto

mahi6a1985
7th December 2012, 13:25
Yes, this is the bottleneck. Every time the widget is shown, the image needs to be scaled. If it is large, scaling takes time. It's better to prescale the image to the size of the widget and then either set it using stylesheets or draw them manually from within the paint event (which will be more efficient).

Hi Wysota,

I am also having the same problem. But in my case there are no images in my widgets, but having lot of controls with style-sheets used to each of the controls for indications.

The below is my screen consists of 6 Push Buttons on bottom of the screen.
In each push button, i am having a widget with 3 table widgets and 10 Q labels and they will be colored using style sheets on diff situations using timers.
8486
The below is one sample widget shown after a push button is clicked
8487

The problem of mine is, as soon as i click on push-button its taking around 6 to 7 secs to display the widget (which i have shown you in the above screen shot.)

The push-button click consists of ui->widget->show(); // which is taking 6 to 7 secs.

where as on the same push-button, if i write ui->widget->setvisible(false);//takes only 1 sec to disappear.

Is there any way of loading the widget faster, like below 2 secs at-least.

any help would make my application faster.

wysota
7th December 2012, 15:04
I don't think show() takes 6-7 seconds. More likely that code that actually shows the widget is taking that long. I suggest you take a profiler and see what is really causing the slowdown. Then you'll know what to optimize.