Results 1 to 7 of 7

Thread: QWidget.show () is slow

  1. #1
    Join Date
    Jan 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default QWidget.show () is slow

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWidget.show () is slow

    Are you using stylesheets for the backgrounds? Are the images being scaled when shown on widgets?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWidget.show () is slow

    Quote Originally Posted by wysota View Post
    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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWidget.show () is slow

    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).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWidget.show () is slow

    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

  6. #6
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    18
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question Re: QWidget.show () is slow

    Quote Originally Posted by wysota View Post
    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.
    2.jpg
    The below is one sample widget shown after a push button is clicked
    1.jpg

    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.
    Last edited by mahi6a1985; 7th December 2012 at 13:41.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWidget.show () is slow

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to show MS Word int QWidget ?
    By luoyes in forum Qt Programming
    Replies: 8
    Last Post: 3rd December 2013, 04:22
  2. setFocus after hide and show qwidget
    By alexandernst in forum Newbie
    Replies: 0
    Last Post: 14th April 2010, 17:25
  3. How show progress of slow a operation?
    By shud in forum Qt Programming
    Replies: 9
    Last Post: 3rd December 2009, 22:10
  4. Replies: 3
    Last Post: 27th February 2008, 08:01
  5. QWidget::exec() and QWidget::show()
    By MarkoSan in forum Qt Programming
    Replies: 6
    Last Post: 18th October 2007, 21:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.