PDA

View Full Version : why My Widget Initialize the display so slow?



tiaoweiliao
20th January 2017, 11:13
hi , all.

Now I have a question , My Widget Initialize the display so slow.

code:
MyWidget * pWidget = new MyWidget();//takes 200~300 ms
ui->stackedWidget->addWidget(MyWidget);//takes 200~300ms

MyWidget is my custom Widget. there are many "MyWidget" in my App.

each MyWidget need invoke "new MyWidget();".

MyWidget have many QWidget,QPushbutton,QLabel etc., about 50.

each MyWidget use Qt Style Sheets and lots of images .

i use qApp->setStyleSheet(style) in function main();

sorry , my english sucks. I wrote down some ideas. Let me know what you cannot read.

Win7 Qt 5.4.2

inter core i5-4460 , ram 8GB

Post your comments here.

d_stranz
20th January 2017, 22:08
Aside from the fact that one of the two lines of code you posted won't even compile, so it obviously isn't your real code... you haven't really told us anything that we can use to determine what could be wrong. There are "many" MyWidget instances in your app. OK, how many is "many"? 4, 40, 400, 4000? How many is "lots" of images? And how are you determining that each of these two lines of code takes 200 - 300 ms to execute?

If each time you create a MyWidget instance you are creating "many" QWidget, QPushButton, and QLabel instances, and each time you load "lots" of images from disk files, then it isn't surprising that it takes a bit of time to do that.