Using different project names results in different UI display speeds
-
Hello, I encountered a strange problem while testing my UI setup.
I have a customized widget which is called "MySpanEdit" and it is decorated by using QSS. I create it 10 of them and put them into layout. It takes 120 ms to initialize this page.MyWidgetDemo::MyWidgetDemo(QWidget* parent) : QWidget(parent) { QWidget* w = new QWidget(this); w->setFixedSize(400, 988); QVBoxLayout* vlayout = new QVBoxLayout(w); QPushButton* btn_show = new QPushButton("click to show widgets"); container = new QWidget(w); container->setObjectName("ParentWidget"); container->setStyleSheet("QWidget#ParentWidget{background-color: rgb(255, 255, 255);}"); vlayout->setContentsMargins(0, 0, 0, 0); vlayout->addWidget(btn_show, 40); connect(btn_show, &QAbstractButton::clicked, this, &MyWidgetDemo::on_btn_show_clicked); } void MyWidgetDemo::on_btn_show_clicked() { QVBoxLayout* hlayout = new QVBoxLayout(container); QElapsedTimer timer; timer.start(); for (int i = 0; i < 10; i++) { MySpanEdit* spanedit = new MySpanEdit(container); spanedit->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); hlayout->addWidget(spanedit); } container->show(); qDebug() << "Widgets set up in " << timer.elapsed() << "ms"; }
Then I modify my CMakeLists.txt, I just change my project name .It only takes 9 ms to show this page after clicking on the button.
cmake_minimum_required(VERSION 3.5) project(MyWidgetTest VERSION 0.1 LANGUAGES CXX) # ... and so on project name
I also try to change the the widget "MySpanEdit" into "QSlider" which is the built in widget in Qt. If I new 10 QSliders, different project names result in 6ms and 0ms being displayed respectively. Why change a project name lead to dramatically difference?
P.S. I'm working on QtCreator 13.0.1 with Qt6.6.3 and MSVC 2019 64bit. -
Hello, I encountered a strange problem while testing my UI setup.
I have a customized widget which is called "MySpanEdit" and it is decorated by using QSS. I create it 10 of them and put them into layout. It takes 120 ms to initialize this page.MyWidgetDemo::MyWidgetDemo(QWidget* parent) : QWidget(parent) { QWidget* w = new QWidget(this); w->setFixedSize(400, 988); QVBoxLayout* vlayout = new QVBoxLayout(w); QPushButton* btn_show = new QPushButton("click to show widgets"); container = new QWidget(w); container->setObjectName("ParentWidget"); container->setStyleSheet("QWidget#ParentWidget{background-color: rgb(255, 255, 255);}"); vlayout->setContentsMargins(0, 0, 0, 0); vlayout->addWidget(btn_show, 40); connect(btn_show, &QAbstractButton::clicked, this, &MyWidgetDemo::on_btn_show_clicked); } void MyWidgetDemo::on_btn_show_clicked() { QVBoxLayout* hlayout = new QVBoxLayout(container); QElapsedTimer timer; timer.start(); for (int i = 0; i < 10; i++) { MySpanEdit* spanedit = new MySpanEdit(container); spanedit->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); hlayout->addWidget(spanedit); } container->show(); qDebug() << "Widgets set up in " << timer.elapsed() << "ms"; }
Then I modify my CMakeLists.txt, I just change my project name .It only takes 9 ms to show this page after clicking on the button.
cmake_minimum_required(VERSION 3.5) project(MyWidgetTest VERSION 0.1 LANGUAGES CXX) # ... and so on project name
I also try to change the the widget "MySpanEdit" into "QSlider" which is the built in widget in Qt. If I new 10 QSliders, different project names result in 6ms and 0ms being displayed respectively. Why change a project name lead to dramatically difference?
P.S. I'm working on QtCreator 13.0.1 with Qt6.6.3 and MSVC 2019 64bit.@CoryChen
There is no obvious reason why project name should make any difference. Did you try (a) repeating your timings over many tests and (b) swapping the order you test them, so the current "faster" one is tested first and the "slower" one tested next, to allow for possible "caching" affecting the timing behaviour? -
@JonB Thank you for answering me.
(a) I try to set my widget in a ScrollArea and use button to create or delete it repeatedly. The widget still shows ten times slower than using new project name.
(b) I change the project name over and over again. Only a certain name cause this kind of delay. I know it doesn't make sense, but it really happened.
I doubt that StyleSheet may cause this trouble. Should I breakdown my project more detail? -
Is one of the projects built in debug mode and the other in release mode?
-
Hi @SimonSchroeder
Nope. I build the projects in Release mode.